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

HTML/XHTML教程
HTML的dl、dt、dd标记制作表格对决Table制作表
HTML网页中的URL表示方式
Web页面 自定义选择框Select
HTML网页制作教程 谨慎使用iframe标记
HTML 网页头部代码全清楚
HTML link标记的rel属性
HTML 代码编写的30条技巧
HTML5 canvas 基本语法
最容易犯的HTML标签错误写法
网页设计参考 firefox 默认样式
将XHTML+CSS页面转换为打印机页面
HTML优化加快网页速度
超链接图标规范:提升文章的可阅读性
标记语言:网页应用CSS样式
标记语言:打印样式
标记语言:CSS布局
标记语言:学完HTML后该学什么?
IE的有条件注释优点和缺点
PSD网页模版转化XHTML的一些理论知识
让XHTML与HTML兼容

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


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