原文地址:http://blog.uoolo.com/Article/16javascript
還有在MVC中使用ueditor:http://blog.uoolo.com/Article/111css
最初百度了一下「編輯器的選擇」,可供選擇的也有好多,使用的較多的有ckeditor、kindeditor、markItUp、ueditor等等。html
一開始考慮到ckeditor使用者多、項目中也用到過、也是國外開源的一個不錯項目,就選擇了ckeditor。在使用一段時間後發現ckeditor有不少地方不符合國人的習慣,首行縮進2個漢字,是我最不能忍的一點。還有就是咱們常常用到的「插入代碼」功能,插入的代碼中的符號居然都被轉義了。java
而ueditor比較符合咱們的使用習慣,之前試用了下,因爲起步晚,有不少bug,沒有選擇他。最近我去ueditor官網看了下,更新到1.2.6.1了,再次試用下,不少bug都修正了。因而乎,如今又用上了他,好,廢話結束。下面具體使用方法:web
1.下載,官網地址:http://ueditor.baidu.com/website/download.html#ueditor 我下載的.net utf-8的。數據庫
2.解壓縮後放入到項目中去編輯器
![ueditor01.png](http://static.javashuo.com/static/loading.gif)
3.在你要使用的地方調用吧,首先引用兩段js,一個配置,一個ueditor網站
1 |
< script src = "../Public/ueditor/ueditor.config.js" type = "text/javascript" ></ script > |
2 |
< script src = "../Public/ueditor/ueditor.all.min.js" type = "text/javascript" ></ script > |
4.而後就是對ueditor的初始化,如下代碼中的temp是獲取數據庫內容信息ui
1 |
< div id = "myEditor" style = "height:500px;" ></ div > |
2 |
< script type = "text/javascript" > |
3 |
var temp = document.getElementById("<%=hd_content.ClientID %>").value; |
4 |
var ue = new baidu.editor.ui.Editor(); |
5 |
ue.render("myEditor"); //這裏填寫要改變爲編輯器的控件id |
6 |
ue.ready(function () { ue.setContent(temp); }) |
5.最後,就是保存數據的方法spa
1 |
< asp:Button ID = "BtnSave" runat = "server" Text = "保存" onclick = "BtnSave_Click" OnClientClick = "return getContent();" CssClass = "cssbtn" /> |
2 |
< script type = "text/javascript" > |
3 |
function getContent() { |
4 |
var temp = UE.getEditor('myEditor').getContent(); |
6 |
document.getElementById("<%=hd_content.ClientID %>").value = temp; |
附:我使用到的hd_content只是爲了中轉內容的。放在body的form內就好了。
1 |
< asp:HiddenField ID = "hd_content" runat = "server" Value = "" /> |
總結:1.ueditor如今版本,路徑真的不要再配置了,ueditor的開發者都已經作好了,比之前方便不少;2..net版本還要注意上傳的問題,有個文件默認編譯的,要改爲內容(若是你是發佈網站),右鍵該文件屬性,就能找到了。
![ueditor02.png](http://static.javashuo.com/static/loading.gif)
哈哈,ueditor真的不錯。