abstract:<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>jq获取随机色</title> <script src="
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jq获取随机色</title>
<script src="jquery-3.3.1.min.js"></script>
</head>
<style>
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>
<body>
<a href="">1</a>
<a href="">2</a>
<a href="">3</a>
<a href="">4</a>
<script>
function aa(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 () {
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 () {
$bg=$(this).css('backgroundColor')
$(this).css('box-shadow','none')
$(this).css('border-radius','50px')
})
})
</script>
</body>
</html>
Correcting teacher:韦小宝Correction time:2019-02-16 09:05:14
Teacher's summary:写的很不错 jQuery 来写这种案例要比JavaScript简单的多