摘要:<!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)//引号末尾空格不能没
批改老师:灭绝师太批改时间:2018-11-22 17:10:23
老师总结:拼接长的时候,你可以换个方式去作业,这个时候就要动脑了哟!