-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.html
60 lines (57 loc) · 2.65 KB
/
example.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://cdn.bootcss.com/summernote/0.8.8/summernote.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/summernote/0.8.8/summernote.min.js"></script>
<!--引入上传附件插件js-->
<script src="./summernote-ext-attachment.js"></script>
</head>
<body>
<div class="summernote" id="summernote"></div>
<script>
$('.summernote').summernote({
height: 200,
//lang: 'zh-CN',
toolbar:[
['style', ['style']],
['font', ['bold', 'underline', 'clear']],
['fontname', ['fontname']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['table', ['table']],
['insert', ['link', 'picture', 'video']],
['view', ['fullscreen', 'codeview', 'help']],
['mybtn',['attachment']] // 引入上传附件按钮
],
callbacks: {
onAttachmentUpload: function (files) { //用法同官方的onImageUpload方法回调 可参考 https://summernote.org/deep-dive
var data = new FormData(); //html5提供的formdata对象,将图片加载为数据的容器
data.append('image_up', files[0]); //加载选中的第一张图片,并给这图片数据标记一个'image_up'的名称
//调用上传附件
$.ajax({
url: 'yourPostUrl', //上传附件请求的路径
method: 'POST', //方法
data: data, //数据
//crossDomain: true, //允许跨域请求(可选)
processData: false, //告诉jQuery不要加工数据
contentType: false, //不要设置Content-Type
success: function (data) {
if (data['message'] == 'success') { //返回值格式 {"message":"success","url":"http://yoururls/example.jpg"}
$("#summernote").summernote('attachment.insertAttachmentNode',data['url']); //调用attachment插件的内部函数插入节点
}
else {
alert(data['message']);
}
}
});
}
}
});
</script>
</body>
</html>