Dom-window对象

来源:互联网 发布:广西南宁智尚网络骗局 编辑:程序博客网 时间:2024/05/21 22:43
动态设置事件:
function f1(){
alert("1");
}
function f2(){
alert("2");
}

<input type="button" onclick="document.ondblclick=f1"/> //注意f1不要加括号,如果加上括号就变成了执行f1函数并把函数的返回值复制给documen.ondblclick
<input type="button" onclick="document.ondblclick=f2"/>

window对象

window对象代表当前浏览器窗口,使用window对象的属性、方法的时候可以省略window,例如window.alert('a') 省略成alert('a')

1.alert()方法弹出消息对话框

2.confirm方法显示“确定”、“取消”对话框,如果按了确定按钮,就返回true,否则返回false

if(confirm("是否继续?")){
alert("确定");
}
else{
alert("取消");
}

3.重新导航到指定的地址:navigate("http://www.baidu.com");

4.setInterval 每隔一段时间执行指定的代码,第一个参数为代码的字符串,第二个参数为间隔时间(单位ms),返回值为定时器的标识
setInterval("alert('起床了!')",500000);

5.cleraInterval取消setInterval的定时执行,相当于Timer中的Enable=false,清除定时器
var intervalId =setInterval("alert('起床了!')",500000);
clearInterval(intervalId);

6.setTimeout是定时执行,但不像setInterval那样是重复地定时执行,只执行一次

7.clearTimeout也是清楚定时。  区分:Interval-间隔 ,timeout-超时 
  var timeoutId =setTimeout("alert('hello')",2000);

 <script type="text/javascript">
        var tid;
        function setTimeOutDemo(){
            //          tid= setTimeout(alert("下课了"),3000);错误的写法
        tid=setTimeout("alert('下课了')",3000);
        }

        function clearTimeOutDemo(){
            if(tid)
            clearTimeout(tid);
        }
 </script>

8.showModalDialog弹出模态对话框。showModalDialog必须在onclick等用户手动触发的事件中才会执行
第一个参数为弹出模态窗口的页面地址

9.showModellessDialog弹出非模态窗口,参数和showModalDialog一样