摘要:<!DOCTYPE html><html><head><meta charset="UTF-8"><!-- 頁面每5秒自動(dòng)刷新 --><meta http-equiv="refresh" content="5"><title>獲取隨機(jī)顏色變化</ti
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- 頁面每5秒自動(dòng)刷新 -->
<meta http-equiv="refresh" content="5">
<title>獲取隨機(jī)顏色變化</title>
<link rel="stylesheet" type="text/css" href="">
<script type="text/javascript" src="jquery-3.3.1.min.js"></script>
<style type="text/css">
.box{border: 10px solid pink;border-radius: 15px;margin:20 auto;overflow: hidden;}
a{display: block; float: left;margin:50px;width: 160px;height: 160px;line-height: 160px;text-align: center;color: #fff;border-radius: 100px;text-decoration: none;border: 1px solid red;}
</style>
<script type="text/javascript">
//顏色的變化
function color_x(tag){
var obj=document.getElementsByTagName(tag);
for (var i = 0; i < obj.length; i++) {
obj[i].style.background='rgb('+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+')';
}
}
$(document).ready(function(){
//調(diào)用顏色變化函數(shù)
color_x('a');
//鼠標(biāo)移動(dòng)上面變化
$('a').mouseover(function(){
$(this).css({
width:'200px',
height:'200px',
lineHeight:"200px",
fontWeight:'bold'
});
})
//離開
$('a').mouseleave(function(){
$(this).css({
width:'160px',
height:'160px',
lineHeight:"160px",
fontWeight:'200'
});
})
})
</script>
</head>
<body>
<div>
<a href="#">NO1</a>
<a href="#">NO2</a>
<a href="#">NO3</a>
<a href="#">NO4</a>
</div>
</body>
</html>
老師我一開始用定時(shí)器,達(dá)不到想要的效果,用定時(shí)器的話該怎么使用
批改老師:天蓬老師批改時(shí)間:2019-01-04 17:58:46
老師總結(jié):Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256, 這個(gè)作業(yè)就是考察你對(duì)原生內(nèi)置的Math對(duì)象的理解, 還有很多方法, 請(qǐng)查看手冊(cè)