<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(/ /ig,'');//去掉 
            str=str.replace(/\s/g,''); //将空格去掉
            return str;
  }
  
  var str="<html> <head>  <title> New Document </title>";
  str=removeHTMLTag(str);
  alert(str);
  </script>
 </body>
</html>