如何使用正则表达式从HTML字符串中删除样式属性 [英] How to Remove Style Attribute From HTML String Using Regex
本文介绍了如何使用正则表达式从HTML字符串中删除样式属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个html字符串,我想删除
推荐答案
如果你想删除内联css,没有必要打扰Regex,只需使用 jQuery [ ^ ]并调用 .removeAttr()方法 [ ^ ]。
例如:
If you want to remove inline css, there is no need to bother Regex, just use jQuery[^] and call .removeAttr() method[^] on the html element.
For example:
<p style="background-color: red">This is another paragraph.</p>
这将删除样式
this will remove the style
(p)。removeAttr(style);
("p").removeAttr("style");
+++++ [第2轮] +++++
在
aspx:
+++++[Round 2]+++++
To do it on code behind
aspx:
<asp:Label ID="Label1" runat="server" Text="Label" style="background-color: red"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
aspx.cs:
aspx.cs:
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Style.Clear();
}
请看一下这个链接,
正则表达式删除| C#在线编译器| .NET小提琴 [ ^ ]
Please Have a look at this link,
regex style remove | C# Online Compiler | .NET Fiddle[^]
这篇关于如何使用正则表达式从HTML字符串中删除样式属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取
|
15天全站免登陆