JavaScript實(shí)現(xiàn)刮刮樂效果
刮刮樂怎么做?
本文實(shí)例為大家分享了JavaScript實(shí)現(xiàn)刮刮樂效果的具體代碼,供大家參考,具體內(nèi)容如下
來這我教你
1、首先準(zhǔn)備好編程軟件webStorm或者eclipse都行2、不會編寫代碼?給你準(zhǔn)備好了3、如下
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Title</title> <style> .outer{ height: 90px; width: 300px; margin: 0 auto; margin-top: 5px; } .box{ height: 70px; width: 70px; background-color: darkgray; line-height: 70px; text-align: center; display: inline-block; margin-left: 5px; } </style></head><body><div class='outer'> <div class='box'></div> <div class='box'></div> <div class='box'></div></div><div class='outer'> <div class='box'></div> <div class='box'></div> <div class='box'></div></div><div class='outer'> <div class='box'></div> <div class='box'></div> <div class='box'></div></div><script> var boxs = document.getElementsByClassName('box'); var item = ['一等獎','二等獎','三等獎','謝謝','謝謝','謝謝','謝謝','謝謝','謝謝',]; for (var i = 0;i<boxs.length;i++){ var box = boxs[i]; box.onclick = function (){ this.style.backgroundColor='red'; //this.innerText='一等獎';//隨即從數(shù)組中獲取內(nèi)容,并且不能重復(fù)! var number = Math.floor(Math.random()*9); this.innerText = item[number]; this.style.color = '#fff'; this.style.verticalAlign = 'top'; } }</script></body></html>
4、這個部分的代碼塊文字內(nèi)容可以自定義,改寫成你想要顯示的內(nèi)容
5、最終網(wǎng)頁顯示界面如下
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 使用vue-cli創(chuàng)建項(xiàng)目并webpack打包的操作方法2. 在vue中獲取wangeditor的html和text的操作3. Python用K-means聚類算法進(jìn)行客戶分群的實(shí)現(xiàn)4. python mysql 字段與關(guān)鍵字沖突的解決方式5. python編寫五子棋游戲6. Java xml數(shù)據(jù)格式返回實(shí)現(xiàn)操作7. 解決Android Studio Design界面不顯示layout控件的問題8. vue style width a href動態(tài)拼接問題的解決9. Java源碼解析之接口List10. python讀取中文路徑時出錯(2種解決方案)
