首页 > Web开发 > 详细

js中设置setInterval的注意点

时间:2016-01-30 22:33:32      阅读:181      评论:0      收藏:0      [点我收藏+]

 

 

 1 <html>
 2 <head>
 3 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 4 <title>Insert title here</title>
 5 
 6 <script type="text/javascript" src="jquery-2.2.0.js"></script>
 7 <script type="text/javascript" src="my.js"></script>
 8 <script type="text/javascript">
 9     // var len = $("img").length;
10     // console.log(len);
11     // $(function(){
12     //     var len = $("img").length;
13     //     console.log(len);    
14     // })
15     
16 </script>
17 </head>
18 <body>
19 
20     <form action="tosubmit" method="post" class="yongle">
21         账号:<input type="text" name="mingzi" /><br>
22         密码:<input type="password" name="mima" /><br> 
23         <input type="submit" value="登陆" />
24     </form>
25     <img /> <img />
26     <a href="dynamicMethod.do" class="yongle">转到dynamicMethod.jsp</a>
27     <a href="dynamicMethod">也是转到dynamicMethod.jsp</a>
28     <a href="dynamicMethod.action">哈哈,也是转到dynamicMethod.jsp</a>
29     时间:<input type="text" size=30 id=‘time‘/>
30 </body>
31 <script type="text/javascript">
32     // var len = $("img").length;
33     // console.log(len);
34     // $(function(){
35     //     var len = $("img").length;
36     //     console.log(len);    
37     // })
38     console.log(typeof $);
39     console.log($("img").length);
40     if(window.innerHeight){
41         alert(支持innerHeight);
42     }else {
43         alert(不支持innerHeight);
44     }
45     function currentTime(){
46         var d = new Date();
47         var curTime = d.toTimeString();
48         // $(‘#time‘).value=curTime;
49         $(#time).attr(value,curTime);
50         // document.getElementById(‘time‘).value=curTime;
51     }
52     window.setInterval("currentTime()",1000);//这个可行,时间会自动更新,注意点就使用window.setInterval(para1,para2)
53                 //的第一个参数是一个function名,一定要用引号包裹起来,否则不会执行,而且浏览器不报错
54     window.setInterval(currentTime(),1000);//这个不可行,但是浏览器不会报错,
55 </script>
56 </html>

 

js中设置setInterval的注意点

原文:http://www.cnblogs.com/Sunnor/p/5171999.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!