第一步,寫入原型
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');
第三步,設(shè)置placeholder
editor.placeholder("請輸入你的內(nèi)容...");
解析:
在原有得基礎(chǔ)上,增加了beforeExecCommand事件,解決了當一開始就上傳圖片等操作時placeholder不會消失得bug,優(yōu)化了內(nèi)容匹配;