博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

包含清除word中的样式的过滤

Posted on 2012-12-19 17:21  人生梦想起飞  阅读(254)  评论(0编辑  收藏  举报

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>

</head>

<body>
 <div id="test" style="float: left; height: 100px; width: 500px; border:1px solid red" contenteditable="true" class="testmr"> 2222</div>

</body>

</html>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(function(){

var updates = function(){
    
    $('.testmr).each(function(){
       
           if($(this).find('img').length>0){
       
         $(this).find('img').each(function(){
                
             if($(this).attr('src').toString().substr(0,44)=='http://res1.starheld.com:8080/group2/M00/0B/'){
          
           return;
          
         }else{
          
          $(this).remove();
          
         }
         
         })
        
         }
       
          if($(this).find('input').length>0){
       
         $(this).find('input').each(function(){
                 
             if($(this).attr('class')=='fill_empty'){
          
           return;
          
         }else{
          
          $(this).remove();
          
         }
         
         })
        
         }
      
        var new_content = $(this).html();
       
       
        var reg_list = [/<\/?[wm]:([^>]+)\/?>([^<]+<\/[wm]:\1>)?/ig, /<(style)>[^<]+<\/\1>/ig, /<(?!img|input)[^>]+>/ig];
        $.each(reg_list, function(i, reg){
        new_content = new_content.replace(reg, '');     
        });
       
      $(this).html(new_content);
      
      
     })
     } 
    
      
  $('.testmr).bind('paste',function(){
      
      setTimeout(function(){updates();}, 10);      
            
    })

  })

</script>