<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<!-- 配置文件 -->
<script src="__PUBLIC__/js/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>
<script type="text/javascript">
var editor;
var _editor;
$(function() {
editor = UE.getEditor('myEditor', {
initialFrameWidth: 800,
initialFrameHeight: 300,
});
//重新实例化一个编辑器,防止在上面的editor编辑器中显示上传的图片或者文件
_editor = UE.getEditor('upload_ue');
_editor.ready(function () {
//隐藏编辑器,因为不会用到这个编辑器实例,所以要隐藏
_editor.hide();
//侦听图片上传
_editor.addListener('beforeInsertImage', function (t, arg) {
//将地址赋值给相应的input,只去第一张图片的路径
$("#picture").attr("value", arg[0].src);
//图片预览
$("#preview").attr("src", arg[0].src);
$("#preview").show();
})
//侦听文件上传,取上传文件列表中第一个上传的文件的路径
_editor.addListener('afterUpfile', function (t, arg) {
$("#file").attr("value", _editor.options.filePath + arg[0].url);
})
});
});
//弹出图片上传的对话框
function upImage() {
var myImage = _editor.getDialog("insertimage");
myImage.open();
}
//弹出文件上传的对话框
function upFiles() {
var myFiles = _editor.getDialog("attachment");
myFiles.open();
}
</script>
</head>
<body>
<script type="text/plain" id="myEditor"></script>
<script type="text/plain" id="upload_ue"></script>
调用的页面: <br><br><br>
<input type="text" id="picture" name="cover" /><a href="javascript:void(0);" οnclick="upImage();">上传图片</a>
<input type="text" id="file" /><a href="javascript:void(0);" οnclick="upFiles();">上传文件</a>
<br><br><br>
预览:<br><br><br>
<img id = 'preview' src="" style="display:none;width: 170px;height:117px" />
</body>
</html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<!-- 配置文件 -->
<script src="__PUBLIC__/js/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>
<script type="text/javascript">
var editor;
var _editor;
$(function() {
editor = UE.getEditor('myEditor', {
initialFrameWidth: 800,
initialFrameHeight: 300,
});
//重新实例化一个编辑器,防止在上面的editor编辑器中显示上传的图片或者文件
_editor = UE.getEditor('upload_ue');
_editor.ready(function () {
//隐藏编辑器,因为不会用到这个编辑器实例,所以要隐藏
_editor.hide();
//侦听图片上传
_editor.addListener('beforeInsertImage', function (t, arg) {
//将地址赋值给相应的input,只去第一张图片的路径
$("#picture").attr("value", arg[0].src);
//图片预览
$("#preview").attr("src", arg[0].src);
$("#preview").show();
})
//侦听文件上传,取上传文件列表中第一个上传的文件的路径
_editor.addListener('afterUpfile', function (t, arg) {
$("#file").attr("value", _editor.options.filePath + arg[0].url);
})
});
});
//弹出图片上传的对话框
function upImage() {
var myImage = _editor.getDialog("insertimage");
myImage.open();
}
//弹出文件上传的对话框
function upFiles() {
var myFiles = _editor.getDialog("attachment");
myFiles.open();
}
</script>
</head>
<body>
<script type="text/plain" id="myEditor"></script>
<script type="text/plain" id="upload_ue"></script>
调用的页面: <br><br><br>
<input type="text" id="picture" name="cover" /><a href="javascript:void(0);" οnclick="upImage();">上传图片</a>
<input type="text" id="file" /><a href="javascript:void(0);" οnclick="upFiles();">上传文件</a>
<br><br><br>
预览:<br><br><br>
<img id = 'preview' src="" style="display:none;width: 170px;height:117px" />
</body>
</html>