百度開源富文字編輯器 UEditor配置:圖片上傳和檔案上傳獨立使用方法

來源:互聯網
上載者:User

標籤:blog   http   io   ar   color   使用   sp   java   for   

使用UEditor編輯器內建的外掛程式實現圖片上傳和檔案上傳功能,這裡通過配置UEditor單獨使用其內建的第三方外掛程式swfupload來實現圖片和檔案的上傳,通過對UEditor配置輕鬆實現圖片批量上傳,檔案披批量上傳

第一步:先配置UEditor

<script src="ueditor/ueditor.config.js"></script><script src="ueditor/ueditor.all.min.js"></script><script type="text/javascript">    var editor = UE.getEditor(‘myEditor‘, {        initialFrameWidth: 800,        initialFrameHeight: 300,    });</script>

第二步:放置編輯器

<script type="text/plain" id="myEditor"></script>

第三步:以上已經把UEditor部署好了,下面實現單獨使用圖片和檔案上傳

<script type="text/javascript">    //重新執行個體化一個編輯器,防止在上面的editor編輯器中顯示上傳的圖片或者檔案    var _editor = UE.getEditor(‘upload_ue‘);    _editor.ready(function () {        //設定編輯器不可用        _editor.setDisabled();        //隱藏編輯器,因為不會用到這個編輯器執行個體,所以要隱藏        _editor.hide();        //偵聽圖片上傳        _editor.addListener(‘beforeInsertImage‘, function (t, arg) {            //將地址賦值給相應的input            $("#picture").attr("value", arg[0].src);            //圖片預覽            $("#preview").attr("src", arg[0].src);        })        //偵聽檔案上傳        _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>

第四步:最後一步,對檔案上傳非常重要,在ueditor檔案夾中找到檔案dialogs\attachment\attachment.html中找到代碼editor.execCommand("insertHTML",str);在上面添加下面的代碼

editor.fireEvent(‘afterUpfile‘, filesList);

然後在<body></body>中隨便找個位置放置這個編輯器

<script type="text/plain" id="upload_ue"></script>

說明:可以把兩次初始化編輯的代碼合并一起放到檔案最後的</body>前面,圖片上傳的配置就不說了,附件中例子已經配置好了,下載下來參考一下就行。轉載請標明出處。

 

源碼下載:點擊下載

百度開源富文字編輯器 UEditor配置:圖片上傳和檔案上傳獨立使用方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.