1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > html 开关按钮 js代码 JavaScript实现开关等效果

html 开关按钮 js代码 JavaScript实现开关等效果

时间:2019-02-23 05:35:49

相关推荐

html 开关按钮 js代码 JavaScript实现开关等效果

废话不多说了,直接给大家贴代码了,具体代码如下所示:

开关灯

html, body {

margin: 0px;

padding: 0px;

width: 100%;

height: 100%;

cursor: pointer;

background-color: white;

}

var oBody = document.getElementById("bodyEle");

oBody.onclick = function () {

var bg = this.style.backgroundColor;

switch (bg) {

case "white":

this.style.backgroundColor = "red";

break;

case "red":

this.style.backgroundColor = "black";

break;

default:

this.style.backgroundColor = "white";

}

}

总结

以上所述是小编给大家介绍的JavaScript实现开关等效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。