dom学习基本代码第一部分
1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>event deal</title> 5 <style type="text/css"> 6 .leixing{color:red;} 7 </style> 8 <script type="text/javascript"> 9 function bodyclick() 10 { 11 alert("first"); 12 alert("second"); 13 } 14 function f1() 15 { 16 alert(1); 17 } 18 function f2() 19 { 20 alert(2); 21 } 22 </script> 23 <script type="text/javascript"> 24 function Confirm() { 25 if (confirm("是否继续")) { 26 alert("继续"); 27 } 28 else { 29 alert("取消"); 30 } 31 } 32 </script> 33 <script type="text/javascript"> 34 var intervalId; 35 function DoSetInterval() 36 {//每隔一定时间执行一次代码 37 intervalId = setInterval("alert(‘hello‘)", 2000);//定时发生代码 38 //返回一个代码,可以通过clearinterval将他清除 39 } 40 setTimeout("alert(‘这个时间到了‘)", 5000);//一定时间后执行此代码,即定时执行一次 41 //clearTimeout(); 42 //也可清除这个定时 43 </script> 44 <script type="text/javascript">//实现标题栏滚动 45 function scroll() 46 { 47 var title = document.title; 48 var top = title.charAt(0); 49 var less = title.substring(1, title.length ); 50 document.title = less + top.toString(); 51 } 52 var inter; 53 function startscroll() 54 { 55 inter = setInterval("scroll()",500); 56 } 57 </script> 58 59 </head> 60 <body onbeforeunload="window.event.returnValue=‘文章会丢失‘"><!--onmousedown="bodyclick()"--> 61 <p>点击我</p> 62 <input type="button" value="f1"onclick="document.ondblclick=f1"/><!--这里定义方式和下面写的方式是一样的效果--> 63 <input type="button" value="f2" onclick="document.ondblclick=f2" /> 64 <input type="button"value="f3"onclick="f1()"> 65 <input type="button" value="f4" onclick="f2()"> 66 <br /> 67 <input type="button"value="确认?"ondblclick="Confirm()"/> 68 <input type="button"value="navigate测试" id="btn"onclick="navigate(‘www.qq.com‘)"/> 69 <br /> 70 <input type="button"value="开始" onclick="DoSetInterval()"/> 71 <input type="button"value="结束"onclick="clearInterval(intervalId)" /> 72 <br /> 73 <input type="button"value="开始滚动"onclick="startscroll()"/> 74 <input type="button" value="停止滚动" onclick="clearInterval(inter)" /> 75 </body> 76 </html>
时间: 2024-10-13 07:07:39