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

HTML/XHTML教程
标记语言:为
将XHTML CSS页面转换为打印机页面
robots.txt详细介绍
HTML和CSS在Flash中的应用
html sub标记和sup标记
HTML 超级链接详细讲解
网页制作前先来看看这些所谓的规范
HTML iframe 用法总结收藏
HTML5 Canvas 起步(2) - 路径
XHTML1.0与HTML兼容指引16条 小结
有效网页表单的八条规则
html pre标记里内容自动换行
设计师 需要学习编写代码吗
使用整洁的HTML标记构建页面
img usemap属性 中国地图链接
HTML5 Canvas标签使用收录
HTML&CSS&JS兼容树(IE,Firefox,chrome)
用js互相调用iframe页面内的js函数
网页制作基础 声明文档类型描述(DTD
HTML5 CSS3新的WEB标准和浏览器支持

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


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