jquery定时器| Id | Title | DateAdded | SourceUrl | PostType | Body | BlogId | Description | DateUpdated | IsMarkdown | EntryName | CreatedTime | IsActive | AutoDesc | AccessPermission |
| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------|
| 14592376| jquery定时器| 2021-03-29T14:54:00| | BlogPost|
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="../js/jquery.min.js"></script> <style> .active{font-size:16px;color:#ffffff; background: #000000;padding:10px;} </style> </head> <body> 数字从1变化到10:<div id="box1">0</div> 自动添加类:<div id="box2">0000000</div> 3秒后自动添加类:<div id="box3">0000000</div> <script> $(function () { fn1("#box1"); fn2("#box2"); //方法执行 setTimeout("fn2('#box3')",3000) //3秒后方法自动执行 }); function fn1(selector){ var num=0; timer=setInterval(function(){ num++; // alert(num) // var text="<span>"+num+",</span>" // $(selector).append(text); //节点添加 $(selector).text(num); if(num==10){ clearInterval(timer); //定时器清除; } },1000); }; function fn2(selector){ $(selector).addClass("active"); }; </script> </body> </html>
| 648658| | 2024-04-29T20:50:00| false| | 2021-03-29T14:53:52.757| true| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="../js/jquery.min.js"></script> <style> .active{font-s| Anonymous| 标签:jquery,function,定时器,selector,num,------------- From: https://www.cnblogs.com/ralphlauren/p/18621238