0

Here is my html code:

<p><span style="background:lime;Color:Red;">Contrary to popular belief, <b><u>Lorem Ipsum is not simply</u></b> random text. It has roots in a piece of classical Latin literature from <span style="background:blue;">45 BC, making it over 2000 years</span> old. Richard McClintock, </span><b>

From above code, i need to remove the background attributes & value using C# from all the spans. The other values in style tag should remain. Eg:

<span style="background:lime;Color:Red;">Contrary to popular belief,.....</span>

should look

<span style="Color:Red;">Contrary to popular belief,.....</span>

Pls help...!

4

3 回答 3

3

使用HtmlAgilityPack

string html = @"<span style=""background:lime;Color:Red;"">Contrary to popular belief,.....</span>";

var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);

foreach (var span in doc.DocumentNode.Descendants("span"))
{
    var style = span.Attributes["style"].Value;
    span.Attributes["style"].Value = String.Join(";", style.Split(';').Where(s => !s.ToLower().Trim().StartsWith("background:")));

}

var newHtml = doc.DocumentNode.InnerHtml;
于 2013-04-22T14:52:42.703 回答
-2

尝试这个

$('span').css("background", "")
于 2013-04-22T14:32:37.697 回答
-3

$('#tagId').removeAttr('style');

于 2013-04-22T14:26:37.477 回答