本文介绍如何使用UEditor实现编辑器的占位符功能,通过监听编辑器的聚焦和失焦事件来显示和隐藏提示文本,确保编辑区域在没有输入内容时显示指定的占位符文字。
var source = UE.getEditor(\’source\’);
UE.Editor.prototype.placeholder = function (justPlainText) {
var _editor = this;
_editor.addListener(\”focus\”, function () {
var localHtml = _editor.getPlainTxt();
if ($.trim(localHtml) === $.trim(justPlainText)) {
_editor.setContent(\”\”);
}
});
_editor.addListener(\”blur\”, function () {
var localHtml = _editor.getContent();
if (!localHtml) {
//_editor.setContent(\'<p style=\”color: #CDCDCD\”>\’ + justPlainText + \'</p>\’);
_editor.setContent(justPlainText);
}
});
_editor.ready(function () {
_editor.fireEvent(\”blur\”);
});
};
source.placeholder(\”此处输入问题描述,请在附件中上传图片……\”);
<script id=\”source\” name=\”workTask.description\” type=\”text/plain\” style=\”width:99%;height:300px\” >${workTask.description}</script>
来源:https://blog.csdn.net/huangbaokang/article/details/103874689
