ueditor设置placeholder(优化版,修复bug)

第一步,写入原型
UE.Editor.prototype.placeholder = function (justPlainText) {
            var _editor = this;
            _editor.addListener("focus", function () {
                var localHtml = _editor.getContent();
                if ($.trim(localHtml) === $.trim('

'+justPlainText+'

')) { _editor.setContent(" "); } }); _editor.addListener("blur", function () { var localHtml = _editor.body.innerHTML; if (localHtml==='

' || localHtml==='


') { _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,优化了内容匹配;

你可能感兴趣的:(ueditor设置placeholder(优化版,修复bug))