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>獲取隨機色</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"> //改變標簽的背景顏色 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ǔ)上稍微改了一下,將獲取背景顏色的代碼單獨提出來 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>
獲取隨機顏色的其他方法暫時沒有想到(或者使用固定的集中顏色從其中隨機?但是這并不是完全隨機,所以放棄這個觀點),難點還是在隨機上,如何隨機獲取,大多還是分別獲取R,G,B的十六進制碼進行拼起來獲取隨機值得到,暫時想不到好辦法,因此只是在老師的基礎(chǔ)上稍微改了一點,將獲取背景顏色的代碼單獨提出來寫(寫了一些都實現(xiàn)不了,暫時放棄,學多了再繼續(xù))。
Correcting teacher:查無此人Correction time:2018-12-06 17:37:29
Teacher's summary:嗯,寫的不錯。邏輯很清晰。每個功能都有很多方法實現(xiàn),多看看別人的寫法就會了。