http://www.cnblogs.com/liszt/archive/2011/08/16/2140007.html
js/javascript删除字符串中的html标签
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,‘‘);//去掉 return str; }
HTML转JS字符串
//Html结构转字符串形式显示 支持<br>换行
function ToHtmlString(htmlStr) { return toTXT(htmlStr).replace(/\<\;br[\&ensp\;|\&emsp\;]*[\/]?\>\;|\r\n|\n/g, "<br/>"); } //Html结构转字符串形式显示 function toTXT(str) { var RexStr = /\<|\>|\"|\‘|\&| | /g str = str.replace(RexStr, function (MatchStr) { switch (MatchStr) { case "<": return "<"; break; case ">": return ">"; break; case "\"": return """; break; case "‘": return "‘"; break; case "&": return "&"; break; case " ": return " "; break; case " ": return " "; break; default: break; } } ) return str; }
时间: 2024-12-16 07:38:46