abstract:!DOCTYPE html><html><head> <title>点击获取随机颜色</title> <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script> <style type=&qu
!DOCTYPE html>
<html>
<head>
<title>点击获取随机颜色</title>
<script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
<style type="text/css">
*{margin: 0;padding: 0;}
a{
float: left;
display: block;
width: 150px;
height: 80px;
line-height: 80px;
text-align: center;
text-decoration: none;
border-radius: 10px;
color: #fff;
margin: 50px;
}
button{float: left;margin-top: 180px;margin-left: -122px;}
</style>
</head>
<body>
<a href="javascript:;" onclick="randBg(this)">0</a>
<a href="javascript:;" onclick="randBg(this)">0</a>
<a href="javascript:;" onclick="randBg(this)">0</a>
<a href="javascript:;" onclick="randBg(this)">0</a>
</body>
</html>
<script type="text/javascript">
// 每次刷新浏览器随机给小球添加颜色
function setBg(tag){
var len = document.getElementsByTagName(tag).length;
console.log(len);
for(var i=0; i<len; i++){
document.getElementsByTagName(tag)[i].style.backgroundColor = 'rgb('+Math.floor(Math.random()*255)+','+Math.floor(Math.random()*255)+','+Math.floor(Math.random()*255)+')';
}
}
// 点击按钮改变小球的颜色
function randBg(obj){
obj.style.backgroundColor = 'rgb('+Math.floor(Math.random()*255)+','+Math.floor(Math.random()*255)+','+Math.floor(Math.random()*255)+')';
var bg = obj.style.backgroundColor;
console.log(bg);
obj.innerHTML = bg;
}
$(document).ready(function(){
setBg('a');
$('a').mouseover(function(){
$bg = $(this).css('backgroundColor');
$(this).css('boxShadow','0px 0px 20px '+$bg);
});
$('a').mouseleave(function(){
$(this).css('boxShadow','none');
$(this).css('borderRadius','10px');
});
});
</script>
Correcting teacher:查无此人Correction time:2019-05-22 09:18:47
Teacher's summary:完成的不错。看你写了不少作业,继续加油。