zoukankan      html  css  js  c++  java
  • Javascript实现"点按钮出随机背景色的"三个DIV

    <!DOCTYPE html>
    <html>
    <head>
        <title>Random_Color-Transformation</title>
        <style type="text/css">
            .div1{
                height: 50px ;
                 320px;
                background-color: red;
                font-size: 0.5em;
                font-weight: bold;
                font-style: italic;
                text-decoration: underline;
            }
            .div2{
                height: 50px ;
                 320px;
                background-color: yellow;
                font-size: 1em;
                font-weight: bold;
                font-style: italic;
                text-decoration: underline;
            }
        </style>
    
        <style type="text/css">
            .div3{
                height: 50px ;
                 320px;
                background-color: green;
                font-size: 2em;
                font-weight: bolder;
                font-style: oblique;
            }
        </style>
    </head>
    <body>
        <div class = "div1" id="00">
            Some contents here!
        </div>
        <input type="button" value="00" onclick = "getBgColor(this);" />
        <div class = "div2" id="01">
            Some contents here!
        </div>
        <input type="button" value="01" onclick = "getBgColor(this);" />
        <div class = "div3" id="10">
            Some contents here!
        </div>
        <input type="button" value="10" onclick = "getBgColor(this);" />
    </body>
    <script type="text/javascript">
        function getBgColor(t){
            var myDiv = document.styleSheets[t.value.substring(0,1)].cssRules[t.value.substring(1,2)].style.backgroundColor;
            alert(myDiv);
            var a = Math.floor(255*Math.random()) + '';
            var b = Math.floor(255*Math.random()) + '';
            var c = Math.floor(255*Math.random()) + '';
            document.styleSheets[t.value.substring(0,1)].cssRules[t.value.substring(1,2)].style.backgroundColor = 'rgb(' + a + ',' + b + ',' + c + ')';
    
        }
    </script>
    </html>
    
  • 相关阅读:
    UOJ Contest #50: Goodbye Jihai
    Codeforces 1278F: Cards
    RS-485总线和Modbus通信协议的关系
    基于Lwip协议栈中独立模式下回调函数的使用
    C语言之链表的使用
    LAN8720A网络模块的使用问题
    C语言的多行宏定义
    C# 解决ListView控件显示数据出现闪屏的问题
    解决使用SecureCRT不能连接Ubuntu的问题
    C++ 与C# 对应的变量互转
  • 原文地址:https://www.cnblogs.com/ZhengPeng7/p/7630059.html
Copyright © 2011-2022 走看看