当前位置: 首页 > 图文教程 > 网页制作 > HTML/XHTML教程 > 清除WORD冗余格式并粘贴

HTML/XHTML教程
添加和删除HTML节点的简单示例
HTML教程:收集的常用的HTML标签(6)
深层优化 提高网站的访问速度的一些技巧
HTML教程:收集的常用的HTML标签(5)
总结XHTML代码常见的应用问题
网页制作中使用规范的HTML代码的几点
学习超级链接A标记
网页元素单位全分析
HTML validate HTML验证
ul和li 基本用法分析
HTML 特殊字符彻底剖析
HTML 行间距的设置方法与问题
按钮在IE中两边被拉伸的 BUG
html 鼠标 css 控制
html 网页跳转代码
当td为空时怎样显示其边框
使用相对宽度调整表格问题
Web分页打印 细线表格+分页打印之终极攻略
W3C教程(12):W3C Soap 活动
W3C教程(11):W3C DOM 活动

HTML/XHTML教程 中的 清除WORD冗余格式并粘贴


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-04   浏览: 129 ::
收藏到网摘: n/a

/ 清除WORD冗余格式并粘贴
function cleanAndPaste( html ) {
 // Remove all SPAN tags
 html = html.replace(/<\/?SPAN[^>]*>/gi, "" );
 // Remove Class attributes
 html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
 // Remove Style attributes
 html = html.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
 // Remove Lang attributes
 html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
 // Remove XML elements and declarations
 html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
 // Remove Tags with XML namespace declarations: <o:p></o:p>
 html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
 // Replace the &nbsp;
 html = html.replace(/&nbsp;/, " " );
 // Transform <P> to <DIV>
 var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ; // Different because of a IE 5.0 error
 html = html.replace( re, "<div$2</div>" ) ;
 
 insertHTML( html ) ;
}