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

HTML/XHTML教程
网页设计中排版与布局小基础
网页上的视觉传达与艺术表现
网页背景设计全攻略(1)
网页配色之黄金分割法
网页设计中的色彩应用
网页建设之色彩应用全攻略
网页背景设计技巧全攻略
Web网页配色方案及安全色谱
网页的审美需求
搭配的艺术--谈主页用色
网站基本配色:专职
网站基本配色:活力
网站基本配色:怀旧
网站基本配色:神奇
网站基本配色:堂皇
网站基本配色:平静
网站基本配色:可靠
JavaScript实用的一些技巧
实现彩色闪烁超链接效果的JS代码
对联广告代码效果之一[普通效果]

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


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