随机色和随机值

原创 2019-02-25 11:35:22 394
摘要://备注:只做到了点击按钮改变颜色,在a链接中加入数字并每次点击数字都为随机值,确实不会<!DOCTYPE html><html><head> <title>获取随机数</title> <script type="text/javascript" src="jquery-3.3.1.min.js&quo

0KOUO])0RL}ZEN{]HYZ6L{9.png

//备注:只做到了点击按钮改变颜色,在a链接中加入数字并每次点击数字都为随机值,确实不会


<!DOCTYPE html>

<html>

<head>

<title>获取随机数</title>

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

<style type="text/css">

a{

float: left;

display: block;

margin:50px;

width:100px;

height:100px;

line-height:100px;

text-align:center;

color:#fff;

border-radius:50px;

text-decoration:block;

}

.bb{color:red;}

</style>


<script type="text/javascript">

//改变标签的背景颜色

function aa(tag){

var len=document.getElementsByTagName(tag).length

for(var i=0;i<len;i++){

//alert(i)

document.getElementsByTagName(tag)[i].style.backgroundColor='rgb('+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+','+Math.floor(Math.random()*256)+')'

}

}

$(document).ready(function(){

aa('a')

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

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

aa('a')

})

})

})


$(document).ready(function(){

//aa('button')

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

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

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

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

$(this).click(function(){

$('a').innerHTML.randomNum(10,20)

})

})


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


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

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

})

})

</script>

</head>

<body>


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

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

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

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

<br><br><br><br><br><br><br><br><br><br>

<button class="box" style="margin-left:350px">刷新新颜色</button>



</body>

</html>


批改老师:韦小宝批改时间:2019-02-25 11:58:29
老师总结:这个也就是相当于颜色随机修改样式一样啊 只不过一个是修改的样式中的颜色 还有一个改的是值啊

发布手记

热门词条