function removeHTMLTag(str) {

<html>
 <head>
  <title> removeHTMLTag.html </title>
  <meta charset="UTF-8">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head>

 <body>

  <script type="text/javascript">
  function removeHTMLTag(str) {
            str = str.replace(/<\/?[^>]*>/g,''); //去除HTML tag
            str = str.replace(/[ | ]*\n/g,'\n'); //去除行尾空白
            //str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
            str=str.replace(/&nbsp;/ig,'');//去掉&nbsp;
            str=str.replace(/\s/g,''); //将空格去掉
            return str;
  }
  
  var str="<html> <head>  <title> New Document </title>";
  str=removeHTMLTag(str);
  alert(str);
  </script>
 </body>
</html>

 

posted @ 2017-11-28 17:13  sky20080101  阅读(131)  评论(0)    收藏  举报