Windows对象
1.alert(message)
<html> <head> <script type="text/javascript"> function display_alert() { alert("I am an alert box!!") } </script> </head> <body> <input type="button" onclick="display_alert()" value="Display alert box" /> </body> </html>
2.confirm(message)
<html> <head> <script type="text/javascript"> function show_confirm() { var r=confirm("Press a button!"); if (r==true) { alert("You pressed OK!"); } else { alert("You pressed Cancel!"); } } </script> </head> <body> <input type="button" onclick="show_confirm()" value="Show a confirm box" /> </body> </html>
3.prompt(text,defaultText)
<html> <head> <script type="text/javascript"> function disp_prompt() { var name=prompt("Please enter your name","") if (name!=null && name!="") { document.write("Hello " + name + "!") } } </script> </head> <body> <input type="button" onclick="disp_prompt()" value="Display a prompt box" /> </body> </html>
4.setInterval(code,millisec[,"lang"])和clearInterval()
<!DOCTYPE html> <html> <head> <title>test</title> </head> <body> <script type="text/javascript"> var ID; function start(){ if (ID == undefined){ //如果为第一次 foo(); ID = window.setInterval(foo,100); } } function foo(){ var timer = new Date().toString().slice(16,24); var ele = document.getElementById("time"); ele.value = timer; } function stop(){ clearInterval(ID); ID = undefined; } // clearInterval(ID); </script> <h5 style="display:inline-block">当前时间为:</h5> <input type="text" id="time" style="display:inline-block " > <button onclick="start()">click</button> <!--绑定事件!--> <button onclick="stop()">stop</button> <!--绑定事件!--> </body> </html>
5.setTimeout(code,millisec)和clearTimeout()
<html> <head> <script type="text/javascript"> var c=0 var t function timedCount() { document.getElementById('txt').value=c c=c+1 t=setTimeout("timedCount()",1000) } function stopCount() { clearTimeout(t) } </script> </head> <body> <form> <input type="button" value="开始计时!" onClick="timedCount()"> <input type="text" id="txt"> <input type="button" value="停止计时!" onClick="stopCount()"> </form> </body> </html>

浙公网安备 33010602011771号