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

<!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 update = function(original){
   var new_content = $('.testmr').html();
  
   var new_content = new_content.replace(/class="[^"]+"/ig, '');
  
   new_content = new_content.replace(/class\="[^"]+"/gi, '');
 
   new_content = new_content.replace(/<h1.*?>(.*?)<\/h1>/ig,"$1");
  
   new_content = new_content.replace(/<h2.*?>(.*?)<\/h2>/ig,"$1");
  
   new_content = new_content.replace(/<h3.*?>(.*?)<\/h3>/ig,"$1");
  
   new_content = new_content.replace(/<h4.*?>(.*?)<\/h4>/ig,"$1");
  
   new_content = new_content.replace(/<h5.*?>(.*?)<\/h5>/ig,"$1");
  
   new_content = new_content.replace(/<h6.*?>(.*?)<\/h6>/ig,"$1");
  
   new_content = new_content.replace(/style\="[^"]+"/gi, '');
  
   alert(new_content);
  $('.testmr').html(new_content);
  }
  
  $('.testmr').bind('paste',function(e){
   var $this = $(this); 
   var original = $this.html();
   setTimeout(function(){update();}, 10);
   
    })
  })

</script>