我想在JavaScript或jQuery中从字符串(而不是对象)中删除所有样式属性。
示例:
var html = "<p style="color:red">my text</p>";
我希望获得如下内容:
<p>my text</p>
有没有可能不调用我们可以在对象上调用的函数(如 removeAttr
)来完成它?
谢谢
我想在JavaScript或jQuery中从字符串(而不是对象)中删除所有样式属性。
示例:
var html = "<p style="color:red">my text</p>";
我希望获得如下内容:
<p>my text</p>
有没有可能不调用我们可以在对象上调用的函数(如 removeAttr
)来完成它?
谢谢
replace
函数在JavaScript中适用的php版本。看看这个能否帮到你。
$("button").click(function() {
$("p").removeAttr("style");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p style="color:red">my text</p>
<button>Remove the style attribute from all p elements</button>