学习掌握了随机色的写法;
学习掌握了获取标签数组的写法;
学习掌握了改变css的写法;
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jq随机背景</title>
<script type="text/javascript" src="jquery-3.3.1.min.js"></script>
<style type="text/css">
div {margin:0 auto;text-align: center;height:100px;width:500px;}
a {
display: block;
float: left;
margin:50px 30px;
height:150px;
width:150px;
border-radius:150px;
line-height: 150px;
text-decoration:none;
color:#fff;
}
</style>
</head>
<body>
<script type="text/javascript">
function aa(tag){
var len=document.getElementsByTagName(tag).length
for(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(){
$(this).css('box-shadow','none')
$(this).css('border-radius','150px')
})
})
</script>
<div>
<a href="">1</a>
<a href="">2</a>
<a href="">3</a>
<a href="">4</a>
</div>
</body>
</html>