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

課后練習-jQuery獲取隨機色

original 2019-03-19 16:45:20 289
abstrait:<!DOCMENT TYPE> <head>     <title>課后練習-jQuery獲取隨機色</title>     <style type="text/css"> *{margin:0;padding:&nbs
<!DOCMENT TYPE>
<head>
    <title>課后練習-jQuery獲取隨機色</title>
    <style type="text/css">
*{margin:0;padding: 0;}
        a {float: left;margin:50px;width: 100px;height:100px;display: block;line-height: 100px;text-align: center;border-radius: 50px;text-decoration: none;color:#fff;}
        button{width: 100px;height: 40px;font-size: 22px;position: absolute;top:200px;left:350px;}
    </style>
    <script src="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
    <script type="text/javascript">
   
        function changColor(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.getElementsByTagName(tag)[i].innerText=Math.floor(Math.random()*10);
            }
        }
        $(function() {
            changColor('a');
            $('button').click(function(){
                changColor('a');
            })
            $('a').hover(
                function(){
                    $bg=$(this).css('backgroundColor');
                    $(this).css('boxShadow','0px 0px 20px '+$bg);
                    $(this).css('borderRadius','10px');
                },
                function(){
                    $bg=$(this).css('backgroundColor');
                    $(this).css('boxShadow','none');
                    $(this).css('borderRadius','50px');
                })
        });
    </script>
</head>
<body>
   <a href="">1</a>
   <a href="">2</a>
   <a href="">3</a>
   <a href="">4</a>
   <button>換色</button>
</body>
</html>

QQ截圖20190319164450.png

Professeur correcteur:天蓬老師Temps de correction:2019-03-19 16:50:31
Résumé du professeur:這個案例中, javascript的標準庫中的math對象很重要

Notes de version

Entrées populaires