本文摘自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怎么判断是否为函数
layui怎么固定表格的表头
js怎么设置css实现隐藏
javascript知识点总结之 文档对象模型
css与javascript的区别是什么
浅谈javascript中的事件委托
javascript中如何声明常量
javascript绑定事件的方法有哪些
window.open()弹窗被浏览器拦截的解决方法
html5和原生app如何进行交互?
更多相关阅读请进入《javascript》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » javascript怎么删除css样式