资料来源:网络整理
时间:2023/2/14 0:10:15 共计:3612 浏览
-
-
-
-
-
-
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;
-
}
-
-
-
-
-
-
-
-
-
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标签缺省或配合混乱。
版权说明:
本网站凡注明“广州京杭 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
欢迎扫描右侧微信二维码与我们联系。