单独调用Ueditor的图片和附件上传功能
2013-11-02 10:41
423 查看
在html中放置编辑器,为了不使独立上传图片或者文件影响到正常的编辑器,这里要多设置一个,myEditor是正常使用的编辑器,upload_ue为隐藏的编辑器。
<script type="text/plain" id="myEditor"></script>
<script type="text/plain" id="upload_ue"></script>
添加图片上传按钮和附件上传按钮:
<input type="text" id="picture" name="cover" /><a href="javascript:void(0);" onclick="upImage();">上传图片</a>
<input type="text" id="file" /><a href="javascript:void(0);" onclick="upFiles();">上传文件</a>
分别实例化两个编辑器,然后为下面的关键代码:
1 <script type="text/javascript">
2 //重新实例化一个编辑器,防止在上面的editor编辑器中显示上传的图片或者文件
3 var _editor = UE.getEditor('upload_ue');
4 _editor.ready(function () {
5 //设置编辑器不可用
6 _editor.setDisabled();
7 //隐藏编辑器,因为不会用到这个编辑器实例,所以要隐藏
8 _editor.hide();
9 //侦听图片上传
10 _editor.addListener('beforeInsertImage', function (t, arg) {
11 //将地址赋值给相应的input,只去第一张图片的路径
12 $("#picture").attr("value", arg[0].src);
13 //图片预览
14 $("#preview").attr("src", arg[0].src);
15 })
16 //侦听文件上传,取上传文件列表中第一个上传的文件的路径
17 _editor.addListener('afterUpfile', function (t, arg) {
18 $("#file").attr("value", _editor.options.filePath + arg[0].url);
19 })
20 });
21 //弹出图片上传的对话框
22 function upImage() {
23 var myImage = _editor.getDialog("insertimage");
24 myImage.open();
25 }
26 //弹出文件上传的对话框
27 function upFiles() {
28 var myFiles = _editor.getDialog("attachment");
29 myFiles.open();
30 }
31 </script>
最后为了能使文件上传后把上传的文件路径填充到input里面去,要添加侦听的事件到dialogs\attachment\attachment.html文件中,在editor.execCommand("insertHTML",str);前面添加,filesList是上传的文件列表,这里只取第一个上传的文件的地址
editor.fireEvent('afterUpfile', filesList);
配置完毕。
<script type="text/plain" id="myEditor"></script>
<script type="text/plain" id="upload_ue"></script>
添加图片上传按钮和附件上传按钮:
<input type="text" id="picture" name="cover" /><a href="javascript:void(0);" onclick="upImage();">上传图片</a>
<input type="text" id="file" /><a href="javascript:void(0);" onclick="upFiles();">上传文件</a>
分别实例化两个编辑器,然后为下面的关键代码:
1 <script type="text/javascript">
2 //重新实例化一个编辑器,防止在上面的editor编辑器中显示上传的图片或者文件
3 var _editor = UE.getEditor('upload_ue');
4 _editor.ready(function () {
5 //设置编辑器不可用
6 _editor.setDisabled();
7 //隐藏编辑器,因为不会用到这个编辑器实例,所以要隐藏
8 _editor.hide();
9 //侦听图片上传
10 _editor.addListener('beforeInsertImage', function (t, arg) {
11 //将地址赋值给相应的input,只去第一张图片的路径
12 $("#picture").attr("value", arg[0].src);
13 //图片预览
14 $("#preview").attr("src", arg[0].src);
15 })
16 //侦听文件上传,取上传文件列表中第一个上传的文件的路径
17 _editor.addListener('afterUpfile', function (t, arg) {
18 $("#file").attr("value", _editor.options.filePath + arg[0].url);
19 })
20 });
21 //弹出图片上传的对话框
22 function upImage() {
23 var myImage = _editor.getDialog("insertimage");
24 myImage.open();
25 }
26 //弹出文件上传的对话框
27 function upFiles() {
28 var myFiles = _editor.getDialog("attachment");
29 myFiles.open();
30 }
31 </script>
最后为了能使文件上传后把上传的文件路径填充到input里面去,要添加侦听的事件到dialogs\attachment\attachment.html文件中,在editor.execCommand("insertHTML",str);前面添加,filesList是上传的文件列表,这里只取第一个上传的文件的地址
editor.fireEvent('afterUpfile', filesList);
配置完毕。
相关文章推荐
- 单独调用Ueditor的图片和附件上传功能
- ueditor单独调用上传附件和图片的功能
- Ueditor 1.4.3 单独调用上传图片,或文件功能
- 单独调用Ueditor的图片上传功能
- ueditor单独图片和附件上传功能
- Ueditor 1.4.3 单独调用上传图片,或文件功能
- 从web编辑器 UEditor 中单独提取图片上传,包含多图片单图片上传以及在线涂鸦功能
- 从web编辑器 UEditor 中单独提取图片上传,包含多图片单图片上传以及在线涂鸦功能
- Ueditor 编译发布后无法使用上传图片、附件等功能
- ueditor单独调用图片上传
- ueditor单独调用图片上传
- ueditor单独调用图片上传
- ueditor调用其中的附件上传功能
- Ueditor 单独使用上传图片及上传附件方法
- 单独使用ueditor的图片上传功能,同时获得上传图片地址和缩略图
- 使用ueditor实现单独的图片上传功能
- 从web编辑器 UEditor 中单独提取图片上传,包含多图片单图片上传以及在线涂鸦功能
- 百度UEditor调用单图片上传功能的解决方法
- 基于SSM使用ueditor编辑框文本、图片上传功能实现
- iOS学习:调用相机,选择图片上传,带预览功能