首页 > 代码库 > 三个按钮 点击可变三种颜色

三个按钮 点击可变三种颜色

技术分享

技术分享

技术分享

 

 

<html>  <head>  <meta charset="utf-8">    <meta name="generator"    content="HTML Tidy for HTML5 (experimental) for Windows https://github.com/w3c/tidy-html5/tree/c63cc39" />    <title></title>    <style>    #div1{    width:100px;    height:100px;    background:red;    }    </style>    <script>    function toYellow(){      var oDiv=document.getElementById(div1);      oDiv.style.background=yellow;    }        function toGreen(){      var oDiv=document.getElementById(div1);      oDiv.style.background=green;    }    function toBlue(){      var oDiv=document.getElementById(div1);      oDiv.style.background=blue;    }    </script>  </head>  <body>  <input type="button" value="变黄" onclick="toYellow()"/>  <input type="button" value="变绿" onclick="toGreen()"/>  <input type="button" value="变蓝" onclick="toBlue()"/>  <div id="div1"></div>  </body></html>

 

三个按钮 点击可变三种颜色