手机屏幕出现html怎样清除

手机屏幕出现html怎样清除,第1张

手机屏幕出现html的清除方法是调用正则表达式清理html标签

1、显示的html代码如下:

<table style="width: 300pxtext-align: center" border="1" cellpadding="5"><tr><th width="75"><strong>Name</strong></th><th colspan="2"><span style="font-weight: bold">Telephone</span></th></tr><tr><td>John</td><td><a href="tel:0123456785">0123 456 785</a></td><td><img src="images/check.gif" alt="checked" /></td></tr></table>

2、开始用js的正则表达式清除

stringWithHTML = stringWithHTML.replace(/<\/?[a-z][a-z0-9]*[^<>]*>/ig, "")

1、正则表达式去掉html标签代码如下:

/// <Header>/// 去除 HTML tag

/// </Header>

/// <param name="HTML">源</param>

/// <returns>结果</returns> public static string StripHTML(string HTML) //google "StripHTML" 得到{ string[] Regexs =

{

@"<script[^>]*?>.*?</script>",

@"<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(\\[""'tbnr]|[^\7])*?\7|\w+)|.{0})|\s)*?(\/\s*)?>",

@"([\r\n])[\s]+",

@"&(quot|#34)",

@"&(amp|#38)",

@"&(lt|#60)",

@"&(gt|#62)",

@"&(nbsp|#160)",

@"&(iexcl|#161)",

@"&(cent|#162)",

@"&(pound|#163)",

@"&(copy|#169)",

@"(\d+)",

@"-->",

@"<!--.*\n"

}

string[] Replaces =

{

"",

"",

"",

"\"",

"&",

"<",

">",

" ",

"\xa1", //chr(161),"\xa2", //chr(162),"\xa3", //chr(163),"\xa9", //chr(169),"",

"\r\n",

""

}

string s = HTML

for (int i = 0i <Regexs.Lengthi++)

{

s = new Regex(Regexs[i], RegexOptions.Multiline | RegexOptions.IgnoreCase).Replace(s, Replaces[i])

}

s.Replace("<", "")

s.Replace(">", "")

s.Replace("\r\n", "")

return s

}

}

2、可以直接复制到txt,然后保存成为.html,在浏览器中设置即可!

JavaScript方式

获取HTML字符串(包含标签),通过正则表达式替换HTML标签,输出替换后的字符串

function deleteTag()

{

  var regx = /<[^>]*>|<\/[^>]*>/gm

  var tagStr = $("#ul_li").html()

  alert("替换之前的字符串:" + tagStr)

  var result = tagStr.replace(regx,"")

  alert("替换之后的字符串:" + result)

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7008115.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-31
下一篇 2023-03-31

发表评论

登录后才能评论

评论列表(0条)

保存