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

HTML/XHTML教程
精通 CSS 滤镜(一)
精通 CSS 滤镜(二)
CSS入门
网站首页head区代码规范
CSS2盒模型的3D示意图
增强网站的可访问性
利用CSS,链接下划线也玩自定义
网页留白的艺术
网页色彩搭配的内涵
巧用CSS制作树状目录
巧用CSS的Border属性制作特效菜单
巧用CSS制作图象特效
巧用CSS制作文字变图象特效
target=_blank不符合标准?
让自己的网站也拥有权威IT报价系统
弹出网页窗口设计全攻略
CSS 循序渐进(四)表里春秋(上)
CSS实用教程(三)
CSS 循序渐进(四)表里春秋(下)
CSS实用教程(一)

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


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