移除CSS样式……求高手解答一下。 现在后台有一个添加文章的功能,文章是用复文本框来添加的内容,数据库的字段类型是text,添加的话,会把文章里面字体的CSS样式什么的也保存下来了,可是现在我要在前台显示文章的内容模块的时候想移除里面的css样式。求解答。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你说的样式是指什么呢?类似这样的<b>粗体</b>?你只要文字,可以用正则去除html标记 如ContentHtml= Regex.Replace(ContentHtml,"<[^>]*>", "");ContentHtml= Regex.Replace(ContentHtml,"\\s+", " "); 或者有没有强制设定div中字体的颜色和大小的,就是说不管这个div里面的字体前面有没有其他定义颜色和大小的,都统一用一个。 你还是都去掉html,然后在每段落的前后加上div /// <summary> /// //将HTML去除 /// </summary> /// <param name="Htmlstring">需要处理的html</param> /// <returns></returns> public static string DelHTML(string Htmlstring) { Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"-->", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"<!--.*", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); //Htmlstring =System.Text.RegularExpressions. Regex.Replace(Htmlstring,@"<A>.*</A>",""); //Htmlstring =System.Text.RegularExpressions. Regex.Replace(Htmlstring,@"<[a-zA-Z]*=\.[a-zA-Z]*\?[a-zA-Z]+=\d&\w=%[a-zA-Z]*|[A-Z0-9]",""); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(amp|#38);", "&", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(lt|#60);", "<", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(gt|#62);", ">", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&#(\d+);", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring.Replace("<", ""); Htmlstring.Replace(">", ""); Htmlstring.Replace("\r\n", ""); return Htmlstring; } 可以添加一格DIV用jquery去掉代码里最里面的style属性 例如<div id=ASD ><table ><tr><td><span Class=FR>a href=/Class/MYSHOP.asp?ID=451><span style='color:#000080;background:#800080'>我的商场</span></a></span></td></tr></table></div> 不行你可以这样尝试:$(document).ready(function(){ $('#msg5 .syzx span').removeAttr("style"); }); 这个需要HTML转换 /// <summary> /// 插入SQL时替换字符 /// </summary> /// <param name="str"></param> /// <returns></returns> public static string Encode(string str) { str = str.Replace("'", "''"); str = str.Replace("\"", """); str = str.Replace("<", "<"); str = str.Replace(">", ">"); str = str.Replace("\n", "<br>"); str = str.Replace("“", "“"); str = str.Replace("”", "”"); return str; } /// <summary> /// 取SQL值时还原字符 /// </summary> /// <param name="str"></param> /// <returns></returns> public static string Decode(string str) { str = str.Replace("”", "”"); str = str.Replace("“", "“"); str = str.Replace("<br>", "\n"); str = str.Replace(">", ">"); str = str.Replace("<", "<"); str = str.Replace(""", "\""); str = str.Replace("''", "'"); return str; } 如果给嵌套网页定义显示的位置 询更改密码的代码? 求一个类似商城详细页面的点击数量加减一的代码 求助 vs2008项目想转换成vs2010 出现这个问题~~ .net达人请进!! 两段代码的区别 基本概念还没有搞清楚... 哪位知道6.0和2003中的有个例子,它表示了3层结构的,我不知道呀。 与IIS和.NET框架有关的一个小问题 在csdn上贴了好几天了没人准确回答,今天再贴一次 如何用JS刷新页面,同时保存JS给控件赋的值啊? mvc参数得不到
你只要文字,可以用正则去除html标记
如
ContentHtml= Regex.Replace(ContentHtml,"<[^>]*>", "");
ContentHtml= Regex.Replace(ContentHtml,"\\s+", " ");
/// <summary>
/// //将HTML去除
/// </summary>
/// <param name="Htmlstring">需要处理的html</param>
/// <returns></returns>
public static string DelHTML(string Htmlstring)
{
Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"-->", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"<!--.*", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); //Htmlstring =System.Text.RegularExpressions. Regex.Replace(Htmlstring,@"<A>.*</A>",""); //Htmlstring =System.Text.RegularExpressions. Regex.Replace(Htmlstring,@"<[a-zA-Z]*=\.[a-zA-Z]*\?[a-zA-Z]+=\d&\w=%[a-zA-Z]*|[A-Z0-9]",""); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(amp|#38);", "&", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(lt|#60);", "<", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(gt|#62);", ">", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", System.Text.RegularExpressions.RegexOptions.IgnoreCase); Htmlstring = System.Text.RegularExpressions.Regex.Replace(Htmlstring, @"&#(\d+);", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
Htmlstring.Replace("<", ""); Htmlstring.Replace(">", ""); Htmlstring.Replace("\r\n", "");
return Htmlstring; }
<div id=ASD >
<table >
<tr>
<td>
<span Class=FR>a href=/Class/MYSHOP.asp?ID=451><span style='color:#000080;background:#800080'>我的商场</span></a>
</span>
</td>
</tr>
</table>
</div>
$('#msg5 .syzx span').removeAttr("style");
});
/// 插入SQL时替换字符
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string Encode(string str)
{
str = str.Replace("'", "''");
str = str.Replace("\"", """);
str = str.Replace("<", "<");
str = str.Replace(">", ">");
str = str.Replace("\n", "<br>");
str = str.Replace("“", "“");
str = str.Replace("”", "”");
return str;
} /// <summary>
/// 取SQL值时还原字符
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string Decode(string str)
{
str = str.Replace("”", "”");
str = str.Replace("“", "“");
str = str.Replace("<br>", "\n");
str = str.Replace(">", ">");
str = str.Replace("<", "<");
str = str.Replace(""", "\"");
str = str.Replace("''", "'");
return str;
}