自动重复调用函数,去除属性

1 <body>
2 
3 年份:<input type="text"  id="A" shx="2016" /><br />
4 <input type="button" value="提交"  onclick="tj()" /><br />
5 
6 例子2:
7 <input type="button" value="同意么?(10)" id="B" disabled="disabled"  />
8 
9 </body>
 1 <script >
 2 function tj()
 3 {
 4     var a = document.getElementById("A");
 5     var a1 = a.value;
 6     var a2 = a.getAttribute("shx");
 7     if(a1 == a2)
 8     {
 9         alert("回答正确")
10     }
11     else
12     {
13         alert("错误回答")
14     }
15 }
16 
17 var b = document.getElementById("B");
18 var n = 10;
19 function sx()
20 {
21     n--;
22     if(n==0)
23     {
24         b.removeAttribute("disabled");
25         b.value="同意";
26         return;
27     }
28     else
29     {
30         b.value = "同意么?("+n+")";    
31     }
32     window.setTimeout("sx()",1000);
33 }
34 window.setTimeout("sx()",1000);
35 
36 </script>
 window.setTimeout("sx()",1000); 
每隔 1 秒,自动调用一次 sx() 函数
结果:







原文地址:https://www.cnblogs.com/wanlibingfeng/p/5622910.html