Day42:JS_DOM
1:BOM:
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 <script> 9 //window 's function 10 //alert('hello')//window.alert('hello') 11 // var ret = window.confirm('hello chen') 12 // console.log(ret) 13 //prompt 14 // var ret = window.prompt('hello chen') 15 // console.log(ret) 16 // open('http://www.baidu.com') 17 18 // setInterval(f,1000); 19 // function f(){ 20 // console.log('hello') 21 // } 22 //###############################################a example: 23 24 </script> 25 </body> 26 </html>
2:One example:
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 <style> 7 #id1{ 8 150px; 9 height: 50px; 10 } 11 </style> 12 </head> 13 <body> 14 <input type="text" id="id1" onclick="begin()"> 15 <button onclick="end()">stop</button> 16 17 <script> 18 19 function showTime() { 20 var current_time=new Date().toLocaleString(); 21 // alert(current_time) 22 var ele=document.getElementById('id1'); 23 ele.value=current_time 24 } 25 var clock1; 26 function begin() { 27 if (clock1==undefined){ 28 showTime(); 29 clock1=setInterval(showTime,1000) 30 } 31 32 33 } 34 35 function end(){ 36 clearInterval(clock1); 37 clock1=undefined 38 } 39 </script> 40 </body> 41 </html>