-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinputPasteContent.html
63 lines (58 loc) · 1.32 KB
/
inputPasteContent.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.box{
width: 400px;
height: 300px;
margin: 200px auto;
}
.con{
width: 400px;
height: 200px;
border: 1px solid #e5e5e5;
overflow-y: auto;
}
</style>
<script src="jquery-1.10.1.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div class="box">
<div class="con" contenteditable="true"></div>
</div>
</body>
</html>
<script type="text/javascript">
$(function(){
$(".con").bind("paste", function(){
var _this = $(this);
setTimeout(function(){
var con = _this.html();
var i, match;
match = con.match(/<[^>]+>/gi);
if (match) {
for (i in match) {
if (!match[i].match(/<(input|div|br).*?(?:>|\/>)/gi)) {
con = con.replace(match[i], '');
}
}
}
match = con.match(/{[^}]+}/gi);
if (match) {
for (i in match) {
if (!match[i].match(/<(input|div|br).*?(?:>|\/>)/gi)) {
con = con.replace(match[i], '');
}
}
}
_this.html(con);
}, 30)
})
})
</script>