abstract:<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>獲取隨機(jī)色</title> <script type="text/javascript" src="jquery.js"></script> <style type="text/css"> a { float:left; display:block; margin:50px; width:100px; line-height: 100px; text-align: center; height:100px; color:#fff; border-radius: 50px; text-decoration: none; } </style> <script type="text/javascript"> //改變標(biāo)簽的背景顏色 function aa(tag) { var len=document.getElementsByTagName(tag).length for(var i=0;i<len;i++){ document.getElementsByTagName(tag)[i].style.backgroundColor=bg() } } function bg(){//在老師的基礎(chǔ)上稍微改了一下,將獲取背景顏色的代碼單獨(dú)提出來(lái) var r=Math.floor(Math.random()*256); var g=Math.floor(Math.random()*256); var b=Math.floor(Math.random()*256); return "rgb("+r+','+g+','+b+")"; }; $(document).ready(function(){ aa('a') $('a').mouseover(function(){ $bg=$(this).css('backgroundColor') $(this).css('box-shadow','0px 0px 20px '+$bg) $(this).css('border-radius','20px ') }) $('a').mouseleave(function(){ $(this).css('box-shadow','none') $(this).css('border-radius','50px ') }) }) </script> </head> <body> <a href="#">1</a> <a href="#">2</a> <a href="#">3</a> <a href="#">4</a> </body> </html>
獲取隨機(jī)顏色的其他方法暫時(shí)沒有想到(或者使用固定的集中顏色從其中隨機(jī)?但是這并不是完全隨機(jī),所以放棄這個(gè)觀點(diǎn)),難點(diǎn)還是在隨機(jī)上,如何隨機(jī)獲取,大多還是分別獲取R,G,B的十六進(jìn)制碼進(jìn)行拼起來(lái)獲取隨機(jī)值得到,暫時(shí)想不到好辦法,因此只是在老師的基礎(chǔ)上稍微改了一點(diǎn),將獲取背景顏色的代碼單獨(dú)提出來(lái)寫(寫了一些都實(shí)現(xiàn)不了,暫時(shí)放棄,學(xué)多了再繼續(xù))。
Correcting teacher:查無(wú)此人Correction time:2018-12-06 17:37:29
Teacher's summary:嗯,寫的不錯(cuò)。邏輯很清晰。每個(gè)功能都有很多方法實(shí)現(xiàn),多看看別人的寫法就會(huì)了。