javascript怎么清除CSS样式?

在js中,可以使用setAttribute方法来设置class属性,替换掉原有class属性,实现删除css样式的功能,下面我们介绍一种更规范的方式,使用removeProperty方法,清除规则样式。

javascript怎么清除CSS样式?

一、使用setAttribute方法清除样式

dom结构

<p id="p" style="color:#FF0000">hello world<p>

javascript

p.setAttribute('style', '');

二、使用removeProperty方法

dom结构

<p id="p" style="color:#FF0000">hello world<p>

javascript

p.style.removeProperty("color");

以上就是javascript怎么清除CSS样式?的详细内容

发布了59 篇原创文章 · 获赞 67 · 访问量 6832

猜你喜欢

转载自blog.csdn.net/BOM485480/article/details/103735575
今日推荐