日期:2014-05-16 浏览次数:20381 次
<html> <head> <title>js模拟选号器</title> <script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.6/jquery.min.js"></script> <script src="http://lib.sinaapp.com/js/jquery-ui/1.8.9/jquery-ui.min.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body id="doc"> <div class="yui3-g" style="font-size:24px"> <div class="num yui3-u"></div> <div class="num yui3-u"></div> <div class="num yui3-u"></div> <div class="num yui3-u"></div> <div class="num yui3-u"></div> <div class="num yui3-u"></div> <div class="num yui3-u"></div> </div> <script> $(document).ready(function() { var findnumid = $("div").children(".num").length, numid, Timer, timer, the_num; function random(start, end) { var between = end - start + 1; return Math.floor(Math.random() * between + start); } function thenum() { the_num = random(0, 9); return the_num; } function time() { for (numid = 0; numid < findnumid; numid++) { var item = $('div .num')[numid]; $('body').find(item).html(thenum()); } }; function display() { var mycars = new Array() mycars[0] = "q"; mycars[1] = "w"; mycars[2] = "e"; mycars[3] = "i"; mycars[4] = "k"; mycars[5] = "j"; mycars[6] = "b"; for (numid = 0; numid < findnumid; numid++) { var item = $('div .num')[numid]; $('body').find(item).html(mycars[numid]); } } $("#start").click(function() { Timer = setInterval(time, 70); }); $("#stop").click(function() { clearInterval(Timer); display(); }); }); </script> <div id="start">开始</div> <div id="stop">停止</div> </body> </html>