天天看點

Ueditor--富文本編輯器附加:

使用步驟如下:

1.引入插件

<script type="text/javascript" src="{{ static_url('ueditor/ueditor.config.js') }}"></script>
<script type="text/javascript" src="{{ static_url('ueditor/ueditor.all.js') }}"></script>
<script type="text/javascript" src="{{ static_url('ueditor/ueditor.parse.js') }}"></script>
           

2.在html頁面中需要顯示富文本編輯器的地方,添加如下代碼:

<label>内容詳情:</label>
//這行代碼在你需要用到的表單元素寫上,ueditor會識别到然後執行個體化一個編輯器到這裡的
<script id="editor" type="text/plain" name="content"></script>
<p class="showInfo"></p>
           

3.建立編輯器

<script>
    //建議使用工廠方法getEditor建立和引用編輯器執行個體,如果在某個閉包下引用該編輯器,直接調用UE.getEditor('editor')
    //就能拿到相關的執行個體
    var ue = UE.getEditor('editor', {
        initialFrameHeight: 300,
        initialFrameWeight: 100,
        toolbars: [
            ['fullscreen', 'source', 'undo', 'redo', 'bold']
        ],
        //autoHeightEnabled: true,
        //autoFloatEnabled: true,
    });
    //初始化編輯器 (該處用于設定編輯器回顯值)
    ue.ready(function () {
        //ue.setContent(formData.content);
        ue.setContent("我是編輯器初始的内容...");
    });
</script>
           

  到這一步你基本的配置就完成了。可以使用編輯器了。

4.但是如果ueditor支援圖檔、文檔、音樂等檔案上傳功能,如果你想要配置上傳路徑,可以修改 ueditor/jsp/config.json。這個檔案對于每一個配置項,都明确的文字說明。附上一段圖檔上傳的配置吧:

<script>
/* 上傳圖檔配置項 */
"imageActionName": "uploadimage", /* 執行上傳圖檔的action名稱 */
"imageFieldName": "upfile", /* 送出的圖檔表單名稱 */
"imageMaxSize": 2048000, /* 上傳大小限制,機關B */
"imageAllowFiles": [".png", ".jpg",".jpeg", ".gif", ".bmp"], /* 上傳圖檔格式顯示 */
"imageCompressEnable": true, /* 是否壓縮圖檔,預設是true*/
"imageCompressBorder": 1600, /* 圖檔壓縮最長邊限制 */
"imageInsertAlign": "none", /* 插入的圖檔浮動方式 */
"imageUrlPrefix": "", /* 圖檔通路路徑字首 */
"imagePathFormat":"_images/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上傳儲存路徑,可以自定義儲存路徑和檔案名格式 */
</script>
           

如果你沒有自己的檔案管理伺服器的話你可以直接修改 imageUrlPrefix 這個屬性,也就是域名就可以了,他會建立一個檔案夾來儲存你上傳的檔案,你也可以修改他的imagePathFormat 屬性來修改他的路徑。

5.你如果覺得界面功能太多想去掉一些的話可以自定義界面的。隻要在ueditor/ueditor.config.js的toolbar中删改配置即可,代碼如下:他的代碼如下:

//工具欄上的所有的功能按鈕和下拉框,可以在new編輯器的執行個體時選擇自己需要的重新定義  

<script>
toolbars: [[
           'fullscreen', 'source', '|', 'undo', 'redo', '|',
           'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
           'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
           'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
           'directionalityltr', 'directionalityrtl', 'indent', '|',
           'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
           'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
           'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'pagebreak', 'template', 'background', '|',
           'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
           'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
           'searchreplace', 'help', 'drafts'
]]  那些自己覺得不需要的去掉就行了
</script>
           

附加:

1.接收富文本框的内容

content1 = ue.getContent(),
           
content2 = ue.getContentTxt(),
           

content1得到的内容會有标簽,content2得到的内容沒有标簽。 

2.下面是轉載的

在渲染 ueditor 的時候,将 ueditor 交給一個全局變量。
<script>
var ue = UE.getEditor('container');
str = ue.getContent();直接擷取文本中的内容
</script>

百度編輯器UEditor常用設定函數大全
線上文檔對UEditor說明不夠全面,收集了一些常用的方法和基本設定,以供參考。
<script>
1、建立編輯器
UE.getEditor('editor', {
initialFrameWidth:"100%" //初始化選項
})
精簡版
UE.getEditor('editor')
2、删除編輯器
UE.getEditor('editor').destroy();
3、設定焦點
UE.getEditor('editor').focus();
4、擷取編輯器内容
UE.getEditor('editor').getContent()
5、編輯器是否有内容
UE.getEditor('editor').hasContents()
6、擷取編輯器内容純文字格式
UE.getEditor('editor').getContentTxt()
7、擷取帶格式的純文字
UE.getEditor('editor').getPlainTxt()
8、啟用編輯器
UE.getEditor('editor').setEnabled();
9、禁止編輯
UE.getEditor('editor').setDisabled('fullscreen');
10、擷取整個html内容
UE.getEditor('editor').getAllHtml()
11、常用設定
imageUrl:UEDITOR_HOME_URL + "../yunserver/yunImageUp.php", //圖檔上傳接口
imagePath:"http://",
scrawlUrl:UEDITOR_HOME_URL + "../yunserver/yunScrawlUp.php",//塗鴉接口
scrawlPath:"http://",
fileUrl:UEDITOR_HOME_URL + "../yunserver/yunFileUp.php",//檔案上傳接口
filePath:"http://",
catcherUrl:UEDITOR_HOME_URL + "php/getRemoteImage.php",//擷取遠端圖檔接口
catcherPath:UEDITOR_HOME_URL + "php/",
imageManagerUrl:UEDITOR_HOME_URL + "../yunserver/yunImgManage.php",//圖檔管理接口
imageManagerPath:"http://",
snapscreenHost:'ueditor.baidu.com',
snapscreenServerUrl:UEDITOR_HOME_URL + "../yunserver/yunSnapImgUp.php",//截圖接口
snapscreenPath:"http://",
wordImageUrl:UEDITOR_HOME_URL + "../yunserver/yunImageUp.php",//word圖檔轉存接口
wordImagePath:"http://", //
getMovieUrl:UEDITOR_HOME_URL + "../yunserver/getMovie.php",//擷取視訊接口
lang:/^zh/.test(navigator.language || navigator.browserLanguage || navigator.userLanguage) ? 'zh-cn' : 'en',
langPath:UEDITOR_HOME_URL + "lang/",
webAppKey:"9HrmGf2ul4mlyK8ktO2Ziayd",
initialFrameWidth:860, //初始化寬度
initialFrameHeight:420, //初始化高度
focus:true //是否焦點
</script>