可编辑的div元素去除粘贴复制带来的额外样式,实现纯文本粘贴
2016-03-03 18:54
781 查看
$(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);
})
})
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);
})
})
相关文章推荐
- 自定义字体样式
- css 行内元素 块元素 替换元素 非替换元素 以及这些元素的width height margin padding 特性
- css3 pointer-events 让对象如透明般直接响应下层对象的鼠标事件
- CSS 设计彻底研究(一)(X)HTML与CSS核心基础
- java EE js css 加载及版本集中管理器
- css样式分类
- CSS3动画属性animation的基本用法
- css display visibility
- CSS----引入方式和常用属性
- 前端性能优化--合理使用CSS Sprites和内联图片
- HTML 样式
- 一些css技巧
- CSS选择器详解
- HTML和CSS <h1> --2-- <h1>
- 使用css3伪元素实现遮罩效果
- css 如何让背景图片拉伸填充避免重复显示
- css3 perspective与translateZ变换
- 礼拜四log~CSS背景设置技巧和java框架某些问题的解决方法
- 谷歌CSS风格规范
- css-selectors