1.在textarea进行操作
<textarea style="width:50%;height:150px;" class="{required:true}" name="question.qstContent" id="qstContent" οnfοcus="if(value=='上传时遇到的特殊公式、表格、符号等 请以图片的形式上传...') {value=''}" οnblur="if(value==''){value='上传时遇到的特殊公式、表格、符号等 请以图片的形式上传...'}">${question.qstContent}</textarea>
2.然后在添加afterFocus和afterBlur事件
//加载编辑器 var editor; KindEditor.ready(function (K) { editor = K.create('textarea[id="qstContent"]', { resizeType: 2, filterMode: false,//true时过滤HTML代码,false时允许输入任何代码。 allowPreviewEmoticons: false, allowUpload: false,//允许上传 syncType: 'auto', width: '620px', minWidth: '10px', minHeight: '10px', height: '300px', newlineTag: 'br',//回车换行br|p afterBlur: function () { editor.sync(); console.log(editor.html()); if (editor.html() == '<br />' || editor.html() == '') { editor.html('上传时遇到的特殊公式、表格、符号等 请以图片的形式上传...'); $("#qstContent").contents().find(".ke-content").css("color","red"); } }, afterFocus: function () { if (editor.html() == '上传时遇到的特殊公式、表格、符号等 请以图片的形式上传...') { editor.html(''); // 输入文字变为黑色 $("#qstContent").contents().find(".ke-content").css("color","#fff"); } }, items: ['source','justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'selectall', 'fontsize', 'forecolor', 'hilitecolor', 'bold', 'underline', 'lineheight'], afterChange: function () { } }); });