<!DOCTYPE?html>
<html>
<head>
<meta?charset="UTF-8">
<title>each</title>
<script?type="text/javascript"?src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
</head>
<body>
????<ul>
????????<li?class="on">0</li>
????????<li?class="on">0</li>
????????<li?class="on">0</li>
????????<li?class="on">0</li>
????????<li?class="on">0</li>
????????<li?class="on">0</li>
????????<li?class="on">0</li>
????????<li?class="on">0</li>
????</ul>
<script?type="text/javascript">
????var?num?=?0,
????timer?=?null;
????$(".on").each(function?(index,?value)?{
????????timer?=?setInterval(function(){
????????????if?(num?==?900)?{
????????????????clearInterval(timer);
????????????}else{
????????????????num++;
????????????}
????????????$(value).text(num);
????????},50)
????})
</script>
</body>
</html>第一個(gè)疑問(wèn)if(num==1000)和if(num==900)得到的最后樣子不同?num==900時(shí),除了最后一個(gè)差幾個(gè)900,其他的都是900,而1000時(shí),li可以全變成1000?第二個(gè)疑問(wèn)定時(shí)器里的函數(shù)寫成這樣為什么只有最后一個(gè)li停了其他的li停不下來(lái)????????timer?=?setInterval(function(){
????????????if?(num?==?998)?{
????????????????clearInterval(timer);
????????????}
????????????num++;
????????????$(value).text(num);
????????},50)
each方法加定時(shí)器的疑問(wèn)?哎呦 無(wú)人問(wèn)津
啊啊啊啊123
2017-05-12 10:54:56