本文主要是介绍KindEditor 添加默认提示信息,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Qt中用这个编辑框可以设置提示信息并且禁用跳转链接
var editor;
var tipFlag = true;
var placeholderText = '';
KindEditor.ready(function(K) {editor = K.create('textarea[name="detailContent"]', {cssData : 'body {font-family:Microsoft YaHei; font-size:12px;} img{ max-width:100%;}',fullscreenMode: true,useContextmenu: false,filterMode: false,afterCreate:function(){//阻止点击链接默认跳转操作var self = this;var doc = this.edit.doc;K(doc).click(function(e) {if (K(e.target).name === 'a') {e.preventDefault();}}); //添加一个提示编辑区var frame = this.edit;K('<textarea class="ph ke-edit-textarea" placeholder = "" style="width: 100%; padding:5px 5px 5px 7px; background-color:transparent; position: absolute;z-index: 10;top: 0;border: 0;overflow: auto;resize: none; font-size:12px;"></textarea>').appendTo(frame.iframe[0].contentDocument.firstChild);frame.iframe[0].contentDocument.firstChild.lastChild.style.height = "100%";frame.iframe[0].contentDocument.firstChild.lastChild.placeholder = placeholderText;var _ua = navigator.userAgent.toLowerCase();var _IE = _ua.indexOf('msie') > -1 && _ua.indexOf('opera') == -1;if(_IE){//IE的事件穿透没做}else{//事件穿透frame.iframe[0].contentDocument.firstChild.lastChild.style.pointerEvents = 'none';}//监听输入事件K(frame.doc)[0].oninput = function(e){if(tipFlag && editor && editor.text() != ''){frame.iframe[0].contentDocument.firstChild.lastChild.style.display = "none";tipFlag = false;}else{if(editor && editor.text() == '' && !tipFlag){frame.iframe[0].contentDocument.firstChild.lastChild.style.display = "block";tipFlag = true;}}};},afterChange:function(){if(editor){var frame = this.edit;if(editor.text() != '' && tipFlag){frame.iframe[0].contentDocument.firstChild.lastChild.style.display = "none";tipFlag = false;}else if(editor.text() == ''&& !tipFlag){frame.iframe[0].contentDocument.firstChild.lastChild.style.display = "block";tipFlag = true;}frame.doc.body.focus(); }},items : ['bold','italic','underline','fontname','fontsize','forecolor','hilitecolor','link','selectall','source']});editor.focus();});//设置提示信息,这个要在html加载完成以后调用function setPlaceholderText(text){var data = utf8to16(base64decode(text)).replace(/\s/gi," ");placeholderText = data;if(editor && editor.edit && editor.edit.iframe[0] && editor.edit.iframe[0].contentDocument && editor.edit.iframe[0].contentDocument.firstChild && editor.edit.iframe[0].contentDocument.firstChild.lastChild){editor.edit.iframe[0].contentDocument.firstChild.lastChild.placeholder='';editor.edit.iframe[0].contentDocument.firstChild.lastChild.placeholder = data;}editor.focus();}
这篇关于KindEditor 添加默认提示信息的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!