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>
<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;