您当前的位置:首页 > 文章 > UEditor编辑器增加placeholder提示

UEditor编辑器增加placeholder提示

作者: 黄宝康 时间:2025-11-11 阅读数:119 人阅读分享到:

本文介绍如何使用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


本站大部分文章、数据、图片均来自互联网,一切版权均归源网站或源作者所有。

如果侵犯了您的权益请来信告知我们删除。邮箱:1451803763@qq.com