///
/// 清除文本中Html的标签
///
///
///
protected string ClearHtml(string Content)
{
COntent= Zxj_ReplaceHtml("&#[^>]*;", "", Content);
COntent= Zxj_ReplaceHtml("?marquee[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?object[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?param[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?embed[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?table[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml(" ", "", Content);
COntent= Zxj_ReplaceHtml("?tr[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?th[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?p[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?a[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?img[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?tbody[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?li[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?span[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?div[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?th[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?td[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?script[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("(Javascript|jscript|Vbscript|vbs):", "", Content);
COntent= Zxj_ReplaceHtml("on(mouse|exit|error|click|key)", "", Content);
COntent= Zxj_ReplaceHtml("<\\?xml[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("<\\/?[a-z]+:[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?font[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?b[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?u[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?i[^>]*>", "", Content);
COntent= Zxj_ReplaceHtml("?strong[^>]*>", "", Content);
string clearHtml = Content;
return clearHtml;
}
///
/// 清除文本中的Html标签
///
/// 要替换的标签正则表达式
/// 替换为的内容
/// 要替换的内容
///
private string Zxj_ReplaceHtml(string patrn, string strRep, string content)
{
if (string.IsNullOrEmpty(content))
{
cOntent= "";
}
Regex rgEx = new Regex(patrn, RegexOptions.IgnoreCase);
string strTxt = rgEx.Replace(content, strRep);
return strTxt;
}
为何要把文字内的html标签去掉呢,是因为在绑定的时候,浏览器会把标签的释义,释义之后会有可能将我们原有的布局打乱。所以,当只展示文字的时候,我们就要这样去做了。遇到这个问题是,在我绑定产品详情的时候遇到的,超过一定字数就截取字符,可以这样又会造成html标签缺省或配合混乱。