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

HTML/XHTML教程
HTML5之后W3C将制定无版本号的HTML
IE6必然灭亡的最新6个理由
网页制作教程:单独对IE6进行兼容
Firefox 3.6频繁崩溃的问题
HTML5的发展:微格式和相关的属性名称
Chrome最新4.0版本支持GreaseMonkey脚本
网页前端常见的攻击方式和预防攻击办法
HTML5标准将把互联网视频扔回到黑暗时代
靠我们自己的力量把IE6推向灭亡
近期热点:HTML5是否真的可以取代Flash
网页知识新手了解:网页设计的发展历史
TinyEditor:简洁且易用的html所见即所得编辑器
ANSI,Unicode,UTF-8网页编码的区别
HTML5实例:20个使用HTML5编写的网站
网页表单设计:主要行为与次要行为
HTML网页实例代码:简洁漂亮的跳转等待页面
经验分享:关于网页布局排版的流程问题
W3C发布7个HTML工作草案
HTML5 旨在解决 Web 中的交互
网页优化的最基础部分:HTML的优化

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


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