假设我有这个字符串:
let string = '<h1 style="lots of class"> </h1><h2> <p style="bunch of class"> </p> <p style="bunch of class"> </p></h2>';
基本上它只是一串像这样的元素,但是是以字符串形式表示:
<h1 style="bunch of class"> </h1>
<h2>
<p style="bunch of class"> </p>
<p style="bunch of class"> </p>
</h2>
使用 jQuery 或纯 JavaScript,我该如何从字符串中删除样式属性?
我已经尝试过这个方法:
$(string).find('h1').removeAttr('style');
但是它没有起作用。
h1
样式? - Kosh