abstrait:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>獲取隨機顏色</title> &nb
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>獲取隨機顏色</title> <script type="text/javascript" src="jquery-3.3.1.min.js"></script> <style type="text/css"> a{ float: left; display: block; margin: 50px; width: 100px; line-height: 100px; text-align: center; height: 100px; color: #000; border-radius: 50px; text-decoration: none; /*background: pink;*/ } </style> <script type="text/javascript"> //改變標簽背景顏色 function bjs(tag){ var len=document.getElementsByTagName(tag).length for(var i=0;i<len;i++){ document.getElementsByTagName(tag)[i].style.backgroundColor='rgb('+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+')' } } $(document).ready(function () { bjs('a') $('a').mouseover(function(){ $bg=$(this).css('backgroundColor') $(this).css('box-shadow','0px 0px 50px '+$bg) $(this).css('border-radius','20px ') }) $('a').mouseleave(function(){ // $bg=$(this).css('backgroundColor') $(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>
'rgb('+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+')'
拼接好長啊
$(this).css('box-shadow','0px 0px 50px '+$bg)//引號末尾空格不能沒
Professeur correcteur:滅絕師太Temps de correction:2018-11-22 17:10:23
Résumé du professeur:拼接長的時候,你可以換個方式去作業(yè),這個時候就要動腦了喲!