JQuery案例二,随机颜色作业和问题

原创 2018-11-09 00:21:25 231
摘要:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> a{ text-decoration:non
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
a{
text-decoration:none;
width:100px;
height:100px;
margin:100px 100px;
text-align:center;
line-height:100px;
display:inline-block;
border-radius:50px;
background-color:red;
color:black;
}
</style>
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
<a href="#">1</a>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">4</a>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
a{
text-decoration:none;
width:100px;
height:100px;
margin:100px 100px;
text-align:center;
line-height:100px;
display:inline-block;
border-radius:50px;
/*background-color:rgb(100,200,100);*/
color:black;
}
</style>
<script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
<a href="#">1</a>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">4</a>

    <script type="text/javascript">
     //改变标签的背景颜色
        function aa(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)+')'
           }
        }
        $(document).ready(function(){
            aa('a')
           $('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 ')
           })
        })
    </script>


</body>
</html>
    </script>

</body>
</html>

为什么我变成8个圈圈了,还有随机数字那段看着糊里糊涂的,我拆散了去书写都没有问题,但是一结合放到rgb里就各种没效果。哪里放分号?还有那里为什么要放+号我是完全分不清了。求老师耐心解答一下

批改老师:韦小宝批改时间:2018-11-09 09:10:57
老师总结:加号是用于连接的!分号就是用于区分的!详细的问题还得标记好到工单中提问哦!这里只能简单的解答一下!继续加油吧!

发布手记

热门词条