abstrait:<!DOCTYPE html><html><head><meta charset="UTF-8"><title>jq獲取隨機(jī)顏色</title><script type="text/javascript" src="jquery-3.3.1.min.js">
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jq獲取隨機(jī)顏色</title>
<script type="text/javascript" src="jquery-3.3.1.min.js"></script>
<style>
a{float: left;display:block;margin: 50px;width: 100px;text-align: center;height: 100px;line-height: 100px;color: #ccc;border-radius: 50px;text-decoration: none;}
</style>
</head>
<body>
<a href="">1</a>
<a href="">2</a>
<a href="">3</a>
<a href="">4</a>
<script type="text/javascript">
//改變標(biāo)簽的背景顏色
function bq(tag) {
var len=document.getElementsByTagName(tag).length//獲取a標(biāo)簽及標(biāo)簽的長(zhǎng)度
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)+')'
}//每循環(huán)一次改變一次背景的顏色
}
$(document).ready(function(){
bq('a')//調(diào)用剛才做的bq這個(gè)函數(shù),傳入的這個(gè)參數(shù)是a鏈接
$('a').mouseover(function(){
$bg=$(this).css('backgroundColor')//獲取當(dāng)前a鏈接的背景色
$(this).css('box-shadow','0px 0px 20px '+$bg)//鏈接根據(jù)當(dāng)前的背景色產(chǎn)生光暈
$(this).css('border-radius','20px ')//鏈接變成圓角
})//鼠標(biāo)移上鏈接時(shí),觸發(fā)一個(gè)事件,改變背景顏色、產(chǎn)生光暈,改變形狀
$('a').mouseleave(function(){
$(this).css('box-shadow','none')
$(this).css('border-radius','50px ')
})//鼠標(biāo)移出時(shí),形狀恢復(fù)圓形,去除光暈效果
})
</script>
</body>
</html>
本作業(yè)涉及的新知識(shí)點(diǎn):
1、math.random():獲取一個(gè)隨機(jī)值
2、math.floor():如果獲取的是小數(shù),進(jìn)行四舍五入
Professeur correcteur:天蓬老師Temps de correction:2019-02-11 11:31:20
Résumé du professeur:其實(shí)就是用原生Math對(duì)象方法來(lái)操作的, 與jQuery無(wú)關(guān)
, 原生的內(nèi)置對(duì)象功能非常豐富,jQuery只是js一個(gè)普通函數(shù)庫(kù)罷 了 , 不要忽略原生js的學(xué)習(xí)