本文摘自PHP中文网,作者青灯夜游,侵删。
js删除样式的方法:1、使用setAttribute()方法,语法“对象.setAttribute("属性名称","")”;2、使用removeProperty()方法,语法“对象.removeProperty("属性名称")”。

本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。
javascript删除css样式
1、使用setAttribute方法清除样式
1 2 3 4 5 6 7 8 9 | < p id = "p" style = "color:#FF0000" >hello world< p >
< button onclick = "myFunction()" >点击按钮,去除样式</ button >
< script >
function myFunction() {
document.getElementById("p").setAttribute('style', '');
}
</ script >
|
效果图:

2、使用removeProperty方法
1 2 3 4 5 6 7 8 9 | < p id = "p" style = "color:palevioletred;" >hello world< p >
< button onclick = "myFunction()" >点击按钮,去除样式</ button >
< script >
function myFunction() {
document.getElementById("p").style.removeProperty("color");
}
</ script >
|
效果图:

【推荐学习:javascript高级教程】
以上就是javascript怎么删除css样式的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
javascript清除数组的方法有哪些
javascript怎么开启
javascript中sort()方法怎么用
javascript如何关闭当前页面
javascript创建元素的方法(代码)
定义javascript数组的方法有哪些
ie怎么设置javascript
javascript和java之间有什么区别
javascript字符串截取方法有哪些?
浅谈js中map和foreach的区别
更多相关阅读请进入《javascript》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » javascript怎么删除css样式