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

HTML/XHTML教程
CSS实用教程(二)
CSS 循序渐进(二)字的艺术
CSS 循序渐进(一)画个瓢
CSS语法手册(二)文本属性
CSS语法手册(四)文本填充,边框,边界和位置属性(二)
CSS语法手册(一)字体属性
CSS语法手册(三)文本填充,边框,边界和位置属性(一)
CSS语法手册(五)颜色和背景属性
CSS语法手册(六)分类属性
捷足先登学用CSS:HTML结构化
HTML语言剖析(4)
HTML语言剖析(3)
HTML语言剖析(1)
HTML语言剖析(2)
网页背景设计全攻略(2)
在 CSS 中关于字体处理效果的思考
常见页面元素遮住菜单解决方法
样 式 表 全 接 触(1)
样 式 表 全 接 触(2)
样 式 表 全 接 触(6)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-04   浏览: 149 ::
收藏到网摘: 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 ) ;
}