abstract:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> &
<!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{text-decoration:none;display:block; width: 100px;height:100px;color: #fff;background:#ccc;float: left;text-align: center;line-height:100px;margin-top: 50px;margin-left: 100px;border-radius: 50px;} </style> <script type="text/javascript"> function discolor(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(){ discolor('a') $('a').mouseover(function(){ $rg=$(this).css('backgroundColor') $(this).css('box-shadow','0px 0px 20px'+$rg) $(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>
总结:
随机获取颜色值函数的 构建
jquery事件
获取并改变CSS样式
Correcting teacher:天蓬老师Correction time:2018-12-16 11:29:01
Teacher's summary:此案例的重点是考察JavaScript原生API中的Math对象上的方法使用,这个对象非常重要,上面有许多有用的方法