// 去除换行<br>
function ClearBr(key) {
key = key.replace(/<\/?.+?>/g, "");
key = key.replace(/[\r\n]/g, ""); return key
}
UE.Editor.prototype.placeholder = function (justPlainText, justPlainText1, justPlainText2) {
var _editor = this;
_editor.addListener("focus", function () {
var localHtml = _editor.getPlainTxt();
if (ClearBr($.trim(localHtml)) === $.trim(justPlainText)) {
_editor.setContent("");
}
});
_editor.addListener("blur", function () {
var localHtml = _editor.getContent();
if (!localHtml) {
_editor.setContent('<span style="color: #aaa">' + justPlainText1 + '</span><br><span style="color: #aaa">' + justPlainText2 + '</span>');//提示语字体灰色
//_editor.setContent(justPlainText);//提示语字体黑色
$("#edui1_wordcount").html("字数统计")
}
});
_editor.ready(function () {
_editor.fireEvent("blur");
});
//此处很重要增加了beforeExecCommand事件,解决了当一开始就上传图片等操作时placeholder不会消失得bug,优化了内容匹配
_editor.addListener('beforeExecCommand', function () {
_editor.focus(true);
});
};
var myeditor = UE.getEditor('txtProcDesc', {
toolbars: [
[
//"fullscreen",
"undo",
"redo",
"|",
"fontfamily",
"fontsize",
"|",
"bold",
"italic",
"underline",
"removeformat",
//"pasteplain",
"|",
"forecolor",
"backcolor",
//"lineheight",
"|",
//"simpleupload",
"insertimage",
]
],
lang: "en",
pasteplain: true
//更多其他参数,请参考ueditor.config.js中的配置项
});
//实例化编辑器example
if ($("元素").val() == "") {
myeditor.placeholder("传值, "传值", "传值");
}
多个参数是为了分行展示placeholder