【JS】颜色切换

Osinghong6个月前 (04-21)成果展示86
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>d24c04429</title>
    <style>
        #show{
            width: 200px;
            height: 200px;
        }
    </style>
<body>
    <div id="show"></div><br>
    <input type="button" value="切换颜色" id="btn" onclick="changeColor()">
    <script>
        function changeColor(){
            var bgColor="#";
            var arr=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];
            for(var i=0;i<6;i++){
            var index=Math.floor(Math.random()*16);
            bgColor+=arr[index];
            }
            document.getElementById("show").style.backgroundColor=bgColor;
        }
    </script>
</body>
</html>


打赏
分享给朋友:

相关文章

【H5】表单11个月前 (11-27)
【JS】三元表达式7个月前 (03-17)
【JS】For语句7个月前 (03-17)
【JS】For语句进阶7个月前 (03-24)
【JS】While循环7个月前 (03-24)
【JS】关于continue7个月前 (03-24)