簡單記錄下,最近工做中要用到一個富文本框,採用以前同事用的ueditor,百度的開源軟件。http://ueditor.baidu.com/doc/dom
他們的API很差看,好辛苦,百度搜了很久也沒什麼太多資料,最後仍是去看源碼,找到了比較好的修改方法:ueditor用iframe實現編輯框,設置body的樣式便可,編輯器
//default font and color
UE.dom.domUtils.setStyles(self.ue.body, {
'color': '#868686','font-family' : "'Microsoft Yahei','Helvetica Neue', Helvetica, STHeiTi, Arial, sans-serif", 'font-size' : '14px'
});this
看網上有人直接改ueditor.all.js文件我以爲太粗暴了(http://blog.csdn.net/yxstars/article/details/44655857),用我這種配置的方式會更好些,且在不一樣的實例中能夠設置不一樣的樣式,這樣更好。spa
順便說一句:修改配置文件ueditor.config.js只是修改可選項,不能修改默認值,因此實例的時候給options,或者editor.setOpt(Object)這些都沒用。.net
################ 下面是個人代碼片斷,我還實現了回車即發送的功能,但願對其餘朋友有所幫助code
#### code begin ############blog
//實例化編輯器
var self = this;
self.ue = UE.getEditor('editor',{toolbars: []});
self.ue.ready(function(){
self.isloadedUE = true;
//set Global.ueditor
Global.ueditor = self.ue;
self.ue.setDisabled();
//default font and color
UE.dom.domUtils.setStyles(self.ue.body, {
'color': '#868686','font-family' : "'Microsoft Yahei','Helvetica Neue', Helvetica, STHeiTi, Arial, sans-serif", 'font-size' : '14px'
});
//回車發送
UE.dom.domUtils.on(self.ue.body, 'keyup', function(event){
if(event.keyCode == 13){
console.log('enter ok');
event.preventDefault();
event.stopPropagation();
self.sendMsg();
}
});
});get
################ code end ############iframe