间隔与延迟:
间隔一段代码;
window.setInterval(“代码”,间隔执行秒数)
延迟一段时间后执行一段代码;
window.setTimeout(“执行代码”,延迟秒数(毫秒)).
对象
1.window.document;
docunment.getElement.ById(“id”)
根据id找到.一个
var a=docunment.getElementById("id")
将找到的元素放在,赋值变量中;
docunment.getElementByName(“名字name”)
找到名字.找出来为数组;
docunment.getElementByClassName(“名字name”)
根据class找到name.找出来的是数组
alert(a.innerText)
获取文字
a.innerHTML
将标签中的HTML代码和文字都获取
2.window.history
window.history.back();页面进行后退;
window.history.forward();页面进行前进
3.window.location
*location;地址栏
var s=window.location.href;获取当前页面的地址*
例;获取id;
<body> <form> 输入<input type="text" id="ee" value="" />/*可输入文本框*/ <input type="button" οnclick="aa()" value="点击" />/*当我点击的时候 */ </form> </body> </html> <script> function aa() { var b=document.getElementById("ee").value/*获取id,ee的value值*/ alert("值为"+b)/*输出*/ } </script>
例;延迟按钮;
<body> <form> <input type="submit" id="b1" name="b1" value="提交(10)" disabled="disabled" />/*一个只能在10s后才可点击的按钮*/ </form> </body> </html> <script> var n=10; var a=document.getElementById("b1");/*根据id找到b1*/ function bian() { n--; if(n==0) { a.removeAttribute("disabled"); a.value="提交"; return; } else { a.value="提交("+n+")"; window.setTimeout("bian()",1000);} } window.setTimeout("bian()",1000); </script>