jquery刷新获取随机色总结

Original 2019-01-13 00:37:26 204
abstract:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml&quo

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>jquery获取随机色</title>

<script type="text/javascript" src="jquery-3.3.1.min.js"></script>

<style type="text/css">

a{

margin: 50px;

float: left;

width: 100px;

line-height: 100px;

height: 100px;

color: #FFF;

border-radius: 50px;

text-decoration: none;

display: block;

background-color: #00F;

text-align: center;

}


button{

height: 30px;

width: 80px;

margin-top: 160px;

position: relative;

float: left;

margin-left:-450px;

border-radius:10px;

background:blue;

color:white;

}

.bt1{


}

</style>

<script>

function bgc(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)+')'


}

       }

   



$(function(){




/* $('a').mouseover(function(){

$bg=$(this).css('backgroundColor')

$(this).css('box-shadow','0px 0px 20px'+$bg)

$(this).css('border-radius','20px')


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


$(this).css('box-shadow','none')

$(this).css('border-radius','50px')

})

*/

$('button').click(function(){

bgc('a')

var x=100

var y=0

var num = parseInt(Math.random()*(x-y+1)+y)


  $bg=$('bgc').css('backgroundColor')

$('a').css('box-shadow','0px 0px 20px '+$bg)

$('a').css('border-radius','20px ')

$('a').html(num)


})



})




</script>

</head>


<body>

<a href="">1</a>

<a href="" >2</a>

<a href="" >3</a>

<a href="" >4</a>

<button>点击变色</button>


</body>

</html>



<!--总结

for()循环语句


random() 获取随机数

html()

parseInt()      解析一个字符串,并返回一个整数。

parseFloat() 解析一个字符串,并返回一个浮点数。


-->


Correcting teacher:天蓬老师Correction time:2019-01-13 09:26:47
Teacher's summary:Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256), 注意在js中, 变量和方法名,是区分 大小写的, 写得不错的

Release Notes

Popular Entries