首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > CSS >

javascript除去HTML标签

2012-10-06 
javascript去除HTML标签javascript去除HTML标签//str 传入的html源文件 noEnter 表示是否去除换行// 不全

javascript去除HTML标签

javascript去除HTML标签//str 传入的html源文件 noEnter 表示是否去除换行
// 不全的话 可依据格式 自己添加.
function html2txt(str,noEnter){
var html = str;
html = html.replace(/<!--[\s\S]*?-->/img, "");//注释
html = html.replace(/<[\/]*table[^>]*>/img, "\n");//table
html = html.replace(/<[\/]*tbody[^>]*>/img, "");//tbody
html = html.replace(/<[\/]*tr[^>]*>/img, "\n");//tr
html = html.replace(/<[\/]*td[^>]*>/img, "\n");//td
html = html.replace(/<[\/]*p[^>]*>/img, "\n");//p
html = html.replace(/<[\/]*a[^>]*>/img, "\n");//a
html = html.replace(/<[\/]*col[^>]*>/img, "\n");//col
html = html.replace(/<[\/]*br[^>]*>/img, "\n");//br
html = html.replace(/<[\/]*[^>]*>/img, "\n");//
html = html.replace(/<[\/]*span[^>]*>/img, "");//span
html = html.replace(/<[\/]*center[^>]*>/img, "");//center
html = html.replace(/<[\/]*ul[^>]*>/img, "");//ul
html = html.replace(/<[\/]*i[^>]*>/img, "");//i
html = html.replace(/<[\/]*li[^>]*>/img, "");//li
html = html.replace(/<[\/]*b[^>]*>/img, "");//b
html = html.replace(/<[\/]*hr[^>]*>/img, "");//hr
html = html.replace(/<[\/]*h\d+[^>]*>/img, "");//h1,2,3,4,5,6
html = html.replace(/<STYLE[\s\S]*?<\/STYLE>/img, "");//样式
html = html.replace(/<script[\s\S]*?<\/script>/img, "");//引用的脚本
//html = html.replace(/<[\?!A-Za-z\][^><]*>/img, "");alert("str:"+html)
html = html.replace(/\r/img, "");//换行
html = html.replace(/\n/img, "\r\n");//回车
html = html.replace(/[ |\s]*\r\n[ |\s]*\r\n/img, "\r\n");
//html = reg.replace(html,@"(\r\n)[^  ]/img,"$1");
html = formatHtml(html);
if(noEnter){
?? html = html.replace(/\r\n/img, "");
?? html = html.replace(/\n/img, "");
?? html = html.replace(/\r/img, "");
}
return (html);
}?



javascript去除HTML标签???天使之翼搜集整理

热点排行