標籤:
首要要載入ueditor的2個js
<script src="../ueditor/ueditor.config.js" type="text/javascript"></script> <script src="../ueditor/ueditor.all.js" type="text/javascript"></script>
<table> <tr> <td> <asp:TextBox ID="txtImgurl" runat="server"></asp:TextBox> <input type="button" id="btnImageUpLoader" value="上傳" onclick="upImage()" /> </td> </tr> <tr> <td> <asp:TextBox ID="txtAttachments" runat="server"></asp:TextBox> <input type="button" id="btnFileUpLoader" value="上傳" onclick="upFile()" /> </td> </tr> </table>
<script type="text/javascript"> UE.getEditor(‘txtContent‘);</script> <script type="text/javascript"> var myEditor = new UE.ui.Editor; myEditor.render(‘btnFileUpLoader‘); myEditor.ready(function() { myEditor.setDisabled(); myEditor.hide(); myEditor.addListener(‘beforeInsertImage‘, function (t, arg) { //因為可以上傳多張,所以就用arg[0] $("#txtImgurl").attr("value", arg[0].src); }); myEditor.addListener(‘afterUpfile‘, function (t, arg) { //這裡這個事件需要到 dialogs\attachment\attachment.html 中 //在editor.execCommand("insertHTML",str);前面添加 $("#txtAttachments").attr("value", arg[0].url); //editor.fireEvent(‘afterUpfile‘, filesList); }); }); function upImage() { var m; m = myEditor.getDialog("insertimage"); m.render(); m.open(); } function upFile() { var f; f = myEditor.getDialog("attachment"); f.render(); f.open(); } //在使用ueditor單獨附件上傳功能的時候點擊"上傳"按鈕時不會出現 檔案上傳對話方塊, //Uncaught TypeError: Cannot read property ‘render‘ of undefined 這是因為在ueditor.config.js //中對toolbars 配置是把 ‘attachment‘ 工具去掉了,只要添加上去就可以了 </script>
ueditor單獨圖片和附件上傳功能