今天給大家介紹一款非常棒的WEB在線富文本編輯器――UMeditor,它是由百度web前端研發(fā)部開發(fā)所見即所得富文本web編輯器UEditor演變的迷你版編輯器,具有輕量,可定制,注重用戶體驗等特點,允許自由使用和修改代碼,適用于前臺快速簡單回復(fù)框或后臺內(nèi)容編輯器。
如何使用?
建立一個demo.html文件,首先在需要添加編輯器的地方加入以下代碼,使用style可以設(shè)置編輯器的寬度和高度。
<script type="text/plain" id="myEditor" style="width:98%;height:240px;"> <p>內(nèi)容區(qū)域</p> </script>
然后,將UMeditor相關(guān)js和css文件加載。相關(guān)文件可以在本站下載或者直接到UMeditor官網(wǎng)下載最新版本。
<script src="http://libs.useso.com/js/jquery/2.1.0/jquery.min.js"></script> <script type="text/javascript" charset="utf-8" src="umeditor.config.js"></script> <script type="text/javascript" charset="utf-8" src="umeditor.min.js"></script> <link href="themes/default/css/umeditor.min.css" type="text/css" rel="stylesheet">
接下來,我們開始調(diào)用編輯器:
<script type="text/javascript"> var um = UM.getEditor('myEditor'); </script>
現(xiàn)在我們可以打開瀏覽器預(yù)覽編輯器效果了。
定制選項
UMeditor提供了豐富的選項設(shè)置,用戶可以根據(jù)自己項目需求適當(dāng)定制。
獲取編輯器里的內(nèi)容可以使用如下代碼,你還可以獲取純文本內(nèi)容。
判斷編輯器是否有內(nèi)容,可以使用如下代碼:
var cont = UM.getEditor('myEditor').hasContents(); if(cont==true){ alert('有內(nèi)容。'); }else{ alert('無內(nèi)容。'); }
如果把編輯器放入表單form中,設(shè)置好action路徑,就可以提交表單傳送編輯器里的內(nèi)容了。如:
<form action="server.php" method="post"> <script id="container" name="content" type="text/plain" style="width:98%;height:240px;">這里寫你的初始化內(nèi)容</script> <button type="submit" class="btn">提交</button> </form>
我們可以設(shè)置工具欄里允許使用的工具圖標(biāo),如以下是簡單的定制幾個常用的工具圖標(biāo):
var editor = UM.getEditor('container',{ toolbar: ['bold italic underline fullscreen', 'link unlink','| justifyleft justifycenter justifyright justifyjustify |', 'emotion image video | map'] });
UMeditor提供了許多工具,可以根據(jù)需求定制,如表格編輯、列表布局、多媒體插入、圖片上傳、地圖調(diào)用等等。UMeditor提供了服務(wù)端的幾種語言版本,主要是用于上傳圖片的處理。用戶可以設(shè)置上傳路徑、上傳文件類型限制、大小限制等等。只需設(shè)置一下即可應(yīng)用。
新聞熱點
疑難解答