我有一个带有html
内容的字符串。我想通过javascript正则表达式来删除style
标签上的style
属性,就像这样:
修改前
<style style="color: red;">
修改后
<style>
你能帮我吗?
我有一个带有html
内容的字符串。我想通过javascript正则表达式来删除style
标签上的style
属性,就像这样:
修改前
<style style="color: red;">
修改后
<style>
你能帮我吗?
$input = '<style style="color: red;">';
$output = preg_replace('/(<[^>]+) style=".*?"/i', '$1', $input);
echo $output;
输出结果将如下所示
<style>
var input = ''
,var output = input.replace()
... - Iris Schafferstr = str.replace(/style="[^"]*"/, "");
node.removeAttribute("style");
// For all tags:
myString = '<style style="color: red;">';
myString = myString.replace(/(<[^>]+) style=".*?"/ig, '$1');
console.log(myString);
或者只是带有样式属性的样式标签:
// For style tags only:
myString = '<style style="color: red;">';
myString = myString.replace(/(<style[^>]*) style=".*?"/ig, '$1');
console.log(myString);
那是一种荒谬的使用方式<style>
,但无论如何。您可以按照以下方式进行:
var styles = document.getElementsByTagName('style');
for ( var i = 0, l = styles.length; i < l ; i++ ){
styles[i].removeAttribute('style');
}
调试它,直到它能正常工作 http://jsfiddle.net/xabe7/
getElementById("id").removeAttribute("style");
$("#id").removeClass("classname");
<style>
标签呢?该标签用于在文档内定义CSS规则... - Lix