abstract:<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, in
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>获取随机颜色</title>
<script src='jquery-3.3.1.min.js'></script>
<style>
a{
display:inline-block;
width: 100px;
height: 100px;
border-radius: 50%;
background: pink;
margin: 50px;
line-height: 100px;
text-align: center;
}
</style>
<script type="text/javascript">
//改变标签的背景颜色
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('border-radius','20px ')
})
$('a').mouseleave(function(){
$(this).css('border-radius','50px ')
})
})
</script>
</head>
<body>
<div>
<a href="#">A</a>
<a href="#">B</a>
<a href="#">C</a>
<a href="#">D</a>
</div>
</body>
</html>
Correcting teacher:天蓬老师Correction time:2019-08-28 16:40:56
Teacher's summary:既然你用了jQuery, 为什么不用jQuery中封装好的一些随机函数呢?