亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

隨機顏色_底部有疑問

Original 2019-02-22 10:30:35 212
abstrakt:<!DOCTYPE html><html><head> <meta charset="utf-8"> <title></title> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script&g

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title></title>

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

<style type="text/css">

a{float: left;display: inline-block;width: 100px;height: 100px;border-radius: 50%;background-color: red;line-height: 100px;text-align: center;text-decoration: none;cursor: pointer;margin-right: 10px;color: black}

</style>


<script type="text/javascript">

$(function(){

var c="rgb("+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+")";


$('a').each(function(){

$(this).css('background-color',"rgb("+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+")");

// $(this).css('background-color',"c");//此處不能是變量c  不然顏色一樣

})


$('a').hover(

function(){

var co=$(this).css('background-color');//獲取當前的元素的顏色

$(this).css({'backgroundColor':co,'box-shadow':'0px 0px 20px'+co,'border-radius':'20%'});


},

function(){

var co=$(this).css('background-color');

$(this).css({'backgroundColor':co,'box-shadow':'none'+co,'border-radius':'50%'});

})


$('a').on('click',function(){


$(this).html(parseInt(Math.random()*999));

$(this).css({'backgroundColor':"rgb("+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+")"});

})


})

</script>


</head>

<body>

<div>

<a href="JavaScript:;">1</a>

<a href="JavaScript:;">2</a>

<a href="JavaScript:;">3</a>

</div>

</body>

</html>



疑問:

為什么文檔就緒函數(shù)下面的 

var c="rgb("+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+")";


$('a').each(function(){

$(this).css('background-color',"rgb("+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+")");

上面的設置顏色為什么不能是預先定義的一個顏色,再設置呢   會是三個球球 顏色一樣;不是應該是三種顏色的嗎

比如:   $(this).css('background-color',"c");

這樣為什么不行?

})


Korrigierender Lehrer:韋小寶Korrekturzeit:2019-02-22 10:54:14
Zusammenfassung des Lehrers:因為那個變量是在點擊事件外部 每次點擊 都會直接過去調(diào)用 你這樣改寫再看看 $('a').on('click',function(){ var c="rgb("+parseInt(Math.random()*255)+","+parseInt(Math.random()*255)+","+p

Versionshinweise

Beliebte Eintr?ge