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

HTML/XHTML教程
初学web标准的几个误区
表格对决CSS--一场生死之战
XHTML基础问答-给初学者
XHTML基础问答
XHTML 1.0
META标签的奥妙
IE支持的html元素的disable在netscape4.76中的实现
HTML组件(HTML COMPONENTS)之十一
HTML组件(HTML COMPONENTS)之十
HTML组件(HTML COMPONENTS)之九
HTML中的图象标签属性
HTML中的表格元素
HTML中Access Key(存取键)的用法
HTML之字体标记
HTML之影像地图
HTML之图形标记
HTML之特殊字符
HTML之清单标记
使用Web标准建站第7天:CSS入门
使用Web标准建站第6天:XHTML代码规范

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


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