2019-8-21 jquery随机色与随机值

原创 2019-08-21 10:18:12 1556
摘要:<!DOCTYPE html><html><head><meta charset="UTF-8"><title>随机值与随机色</title><script src="https://code.jquery.com/jquery-3.4.1.js"></script&g

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>随机值与随机色</title>

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

<style>

a{

display:block;

width:100px;

height:100px;

color:#fff;

float: left;

margin:30px;

border-radius: 50%;

text-decoration: none;

text-align: center;

line-height: 100px;

font-size: 20px;

}

button{

float:left;

}

</style>

</head>

<body>

<script>

$(document).ready(function(){

function ref(){

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

$(this).css('backgroundColor','rgb('+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+')');

})

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

$(this).text(Math.floor(Math.random()*99));

})

}

ref();

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

ref();

})

})

</script>

<button>刷新</button>

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

<a href=""></a>

<a href=""></a>

<a href=""></a>

<a href=""></a>

<a href=""></a>

</body>

</html>


批改老师:天蓬老师批改时间:2019-08-22 15:31:45
老师总结:获取随机数, 可以完成很多有意思的东西, 例如随机从数组中取一个数, 抽奖等

发布手记

热门词条