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

HTML/XHTML教程
一些不太常用的XHTML标签用法以及实例
网页中图片的设置涉及的三个问题
商业HTML邮件的制作建议
HTML Marquee 字符片段滚动
DOCTYPE 文档类型声明(网页爱好者必看)
纯HTML标签你熟悉多少?
HTML元素的ID和Name属性的区别
HTML meta的大作用
HTML标签tbody的用法与说明
HTML 特殊字符转换表
HTML基础 HTML的组成结构
HTML基础之HTML内容细则
Shtml 精简教程
浅谈html table 标签
html Frame、Iframe、Frameset 的区别
HTML 网页页面切换的各种变换效果
HTML的10个表格相关标记
让IE8启动IE7兼容模式的代码
HTML 结构化实现方法
xhtml的块级标记小结

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


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