js点击变色小案例

2020-11-15  本文已影响0人  她她她i_1555

版本一(js行内式写法)

css部分
html,body{
            height: 100%;
            width: 100%;
        }

html部分

<input type="button" value=" 点我变蓝" onclick="document.body.style.background='blue'">
<input type="button"  value="点我变红" onclick="document.body.style.background='red'">
 <input type="button" value="点我变黄" onclick="document.body.style.background='yellow'">

注释内容

版本二(js行内式写法)

css部分

html,body{
            height: 100%;
            width: 100%;
        }

html部分

  <button id="ben">按钮</button>

js部分

var redben=document.getElementById("ben"):
onclick=function(){
 document.body.style.background = "red";
}
注释内容
上一篇 下一篇

猜你喜欢

热点阅读