本文實例講述了js實現網頁抽獎的方法。分享給大家供大家參考。具體如下:
這段網頁抽獎程序,基于javascript代碼實現,簡單的演示如何使用JS來實現抽獎功能,點擊“開始抽獎”按鈕,程序即開始抽獎了,需要停止的時候按“停止”,以前發過類似的抽獎程序有幾個了,有興趣的自己在本站網頁特效欄目搜索“抽獎”看下。
運行效果如下圖所示:
具體代碼如下:
<!DOCTYPE html><html lang="zh"><head><title>抽獎程序</title><script type="text/javascript"> var randNum=Math.random()*10;function testTime(){document.getElementById("testtime").innerHTML="<h2>"+Math.floor(Math.random()*10)+"</h2>";}function setTime(mark){timer=null;timer=setInterval(testTime,12);if(mark=='stop'){ clearInterval(timer);}return timer;}function clearTime(timer){ }</script><style type="text/css"><!--body {font-family: Arial;color:#fff;margin: 0px;padding: 0px;background:#000;text-align:center;}#happyness{font-size:186px;line-height:186px;margin-top:100px;}--></style></head><body></body><button onClick="timer=setInterval(testTime,12);" value="" style="width:100px;height:30px">開始抽獎</button><button onClick="clearInterval(timer);" value="Stop" style="width:100px;height:30px">停止</button><div id="testtime" style="font-size:25px"></div></html>
希望本文所述對大家的javascript程序設計有所幫助。
新聞熱點
疑難解答