js学习笔记:setInterval()的进一步理解
- <head>
- <style type="text/css">
- #s{border:1px solid #000;width:100px;height:100px;top:300px;left:300px;cursor:pointer;}
- </style>
- </head>
- <body>
- <script type="text/javascript">
- function test(o){
- var i = 1;
- if(typeof o == "string"){
- var j = 2;
- for(var k = 0;k < 10;k++){
- alert(k);
- }
- alert(k);
- }
- alert(j);
- }
- function f(){
- var sa = document.getElementsByTagName("a");
- for(var i = 0;i < sa.length;i++){
- sa[i].onclick = function(){alert(this.innerHTML)};
- }
- }
- function printDate(){
- var d = new Date();
- var s = document.getElementById("s");
- s.innerHTML = d.toLocaleString();
- }
- function moveDiv(divName){
- var name = document.getElementById(divName);
- name.style.position = "absolute";
- var n = name.offsetWidth;;
- function change(){
- if(n<290){
- name.style.width = n + "px";
- name.style.height = n + "px";
- name.style.top = 300- n/3 + "px";
- name.style.left = 300 - n/3 + "px";
- n = n+10;
- }
- }
- function small(){
- if(n>110){
- name.style.width = n + "px";
- name.style.height = n + "px";
- name.style.top = 300- n/3 + "px";
- name.style.left = 300 - n/3 + "px";
- n = n-10;
- }
- }
- if(name.className == "c"){
- name.onclick = function(){
- name.className = "d";
- setInterval(change,10);
- };
- }
- else{
- name.onclick = function(){
- name.className = "c";
- setInterval(small,10);
- };
- }
- }
- window.onload = function(){
- f();
- moveDiv("s");
- };
- </script>
- <div id="s" class="c">dd</div>
- <a id="sd" href="#nogo">click here</a>
- <a href="#nogo">click here too</a>
- </body>
请您留下评论