js学习笔记:setInterval()的进一步理解

  1. <head>
  2.         <style type="text/css">
  3.         #s{border:1px solid #000;width:100px;height:100px;top:300px;left:300px;cursor:pointer;}
  4.         </style>
  5.     </head>
  6.     <body>
  7.         <script type="text/javascript">
  8.             function test(o){
  9.                 var i = 1;
  10.                 if(typeof o == "string"){
  11.                     var j = 2;
  12.                     for(var k = 0;k < 10;k++){
  13.                         alert(k);
  14.                     }
  15.                     alert(k);
  16.                 }
  17.                 alert(j);
  18.             }
  19.             function f(){
  20.                 var sa = document.getElementsByTagName("a");
  21.                 for(var i = 0;i < sa.length;i++){
  22.                     sa[i].onclick = function(){alert(this.innerHTML)};
  23.                 }
  24.             }
  25.             function printDate(){
  26.                 var d = new Date();
  27.                 var s = document.getElementById("s");
  28.                 s.innerHTML = d.toLocaleString();
  29.             }
  30.             function moveDiv(divName){
  31.                     var name = document.getElementById(divName);
  32.                     name.style.position = "absolute";
  33.                     var n = name.offsetWidth;;
  34.                     function change(){
  35.                         if(n<290){
  36.                             name.style.width = n + "px";
  37.                             name.style.height = n + "px";
  38.                             name.style.top = 300- n/3 + "px";
  39.                             name.style.left = 300 - n/3 + "px";
  40.                             n = n+10;
  41.                         }
  42.                     }
  43.                     function small(){
  44.                         if(n>110){
  45.                             name.style.width = n + "px";
  46.                             name.style.height = n + "px";
  47.                             name.style.top = 300- n/3 + "px";
  48.                             name.style.left = 300 - n/3 + "px";
  49.                             n = n-10;
  50.                         }
  51.                     }
  52.                     if(name.className == "c"){
  53.                         name.onclick = function(){
  54.                             name.className = "d";
  55.                             setInterval(change,10);
  56.                         };
  57.                     }
  58.                     else{
  59.                         name.onclick = function(){
  60.                             name.className = "c";
  61.                             setInterval(small,10);
  62.                         };
  63.                     }
  64.                 }
  65.             window.onload = function(){
  66.                 f();
  67.                 moveDiv("s");
  68.             };
  69.         </script>
  70.         <div id="s" class="c">dd</div>
  71.         <a id="sd" href="#nogo">click here</a>
  72.         <a href="#nogo">click here too</a>
  73.     </body>

相关文章

请您留下评论

Tags:
Separate individual tags by commas