简单记录下,最近工做中要用到一个富文本框,采用以前同事用的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