javascript浏览器对象(window/计时器/History/location/navigator/screen/document)

1、window对象


2、计时器方法


setInterval(代码,交互时间);
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计时器</title>
<script type="text/javascript">
  var int=setInterval(clock, 100)
  function clock(){
    var time=new Date();
    document.getElementById("clock").value = time;
  }
</script>
</head>
<body>
  <form>
    <input type="text" id="clock" size="50"  />
  </form>
</body>
</html>
clearInterval(id_of_setInterval)      id_of_setInterval:由 setInterval() 返回的 ID 值。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计时器</title>
<script type="text/javascript">
   function clock(){
      var time=new Date();                     
      document.getElementById("clock").value = time;
   }
// 每隔100毫秒调用clock函数,并将返回值赋值给i
     var i=setInterval("clock()",100);
</script>
</head>
<body>
  <form>
    <input type="text" id="clock" size="50"  />
    <input type="button" value="Stop" οnclick="clearInterval(i)"  />
  </form>
</body>
</html>
setTimeout(代码,延迟时间);
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
  setTimeout("alert('Hello!')", 3000 );  //3000单位是ms
</script>
</head>
<body>
</body>
</html>

当按钮被点击后,输入域便从0开始计数。

<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
var num=0;
function numCount(){
 document.getElementById('txt').value=num;
 num=num+1;
 setTimeout("numCount()",1000);
 }
</script>
</head>
<body>
<form>
<input type="text" id="txt" />
<input type="button" value="Start" onClick="numCount()" />
</form>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
  var num=0,i;
  function timedCount(){
    document.getElementById('txt').value=num;
    num=num+1;
    i=setTimeout(timedCount,1000);
  }
    setTimeout(timedCount,1000);
  function stopCount(){
    clearTimeout(i);
  }
</script>
</head>
<body>
  <form>
    <input type="text" id="txt">
    <input type="button" value="Stop" onClick="stopCount()">
  </form>
</body>
</html>


3、window.History记录了用户曾经浏览过的页面(URL),并可以实现浏览器前进与后退相似导航的功能。(能不用最好不用)



<script type="text/javascript">
  var HL = window.history.length;
  document.write(HL);
</script>

back()相当于go(-1)

forward()相当于go(1)

window.history.go(number); //加载某个具体的界面

http://www.jb51.net/article/32749.htm

4、location用法,可查看url路径,刷新界面

location.[属性|方法]



5、Navigator 对象包含有关浏览器的信息,通常用于检测浏览器与操作系统的版本。


userAgent返回用户代理头的字符串表示(就是包括浏览器版本信息等的字符串)

6、screen对象

window.screen.属性


<script type="text/javascript">
  document.write( "屏幕宽度:"+screen.width+"px<br />" );
  document.write( "屏幕高度:"+screen.height+"px<br />" );
</script>


7、document

document对象表示当前页面。由于HTML在浏览器中以DOM形式表示为树形结构,document对象就是整个DOM数的根节点。

document的title属性是从HTML文档中的<title>xxx</title>读取的,但是可以动态改变

document.title = '努力学习JavaScript!';
JavaScript可以通过document.cookie读取到当前页面的Cookie

document.cookie; 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值