对于标准textareas,我使用此
plugin创建占位符.我怎样才能扩展tinymce以便这也能以这种方式工作.
例如,从textarea属性读取默认值,然后在用户关注iframe时清除.
与CKEditor类似:http://alfonsoml.blogspot.com.es/2012/04/placeholder-text-in-ckeditor.html
解决方法
如果没有占位符属性,我收到错误.
我结合了这个答案的代码:
jQuery hasAttr checking to see if there is an attribute on an element获取下面修改的代码处理该场景:
setup: function(ed) { // Set placeholder var tinymce_placeholder = $('#'+ed.id); var attr = tinymce_placeholder.attr('placeholder'); // For some browsers,`attr` is undefined; for others,// `attr` is false. Check for both. if (typeof attr !== 'undefined' && attr !== false) { var is_default = false; ed.onInit.add(function(ed) { // get the current content var cont = ed.getContent(); // If its empty and we have a placeholder set the value if(cont.length == 0){ ed.setContent(tinymce_placeholder.attr("placeholder")); // Get updated content cont = tinymce_placeholder.attr("placeholder"); } // convert to plain text and compare strings is_default = (cont == tinymce_placeholder.attr("placeholder")); // nothing to do if (!is_default){ return; } }); ed.onMouseDown.add(function(ed,e) { // replace the default content on focus if the same as original placeholder if (is_default){ ed.setContent(''); } }); } }