第一步,写入原型
UE.Editor.prototype.placeholder = function (justPlainText) {
var _editor = this;
_editor.addListener("focus", function () {
var localHtml = _editor.getContent();
if ($.trim(localHtml) === $.trim('<p>'+justPlainText+'</p>')) {
_editor.setContent(" ");
}
});
_editor.addListener("blur", function () {
var localHtml = _editor.body.innerHTML;
if (localHtml==='<p> </p>' || localHtml==='<p><br></p>') {
_editor.setContent(justPlainText);
}
});
_editor.ready(function () {
_editor.fireEvent("blur");
});
_editor.addListener('beforeExecCommand',function () {
editor.focus(true);
});
};
第二步,初始化实例
var editor = UE.getEditor('editor');
第三步,设置placeholder
editor.placeholder("请输入你的内容...");
解析:
在原有得基础上,增加了beforeExecCommand
事件,解决了当一开始就上传图片等操作时placeholder不会消失得bug,优化了内容匹配;