我写这个是为了作为textarea[placeholder]
和 tinymce 的基本占位符。
//set up a new editor functionality
setup: function(ed) {
// Set placeholder
var $editorMce = $('#'+ed.id);
var editorMce_placeholder = $editorMce.attr("placeholder");
if(editorMce_placeholder.length){
var is_placeholder = 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(editorMce_placeholder);
// Get updated content
cont = editorMce_placeholder;
}
// convert to plain text and compare strings
is_placeholder = (cont == editorMce_placeholder);
// nothing to do
if (!is_placeholder){
return;
}
});
ed.onMouseDown.add(function(ed,e) {
// replace the default content on focus if the same as original placeholder
if (is_placeholder){
ed.setContent('');
}
});
ed.onSaveContent.add(function(ed, o) {
// replace the content back to empty if the same as placeholder
if(editorMce_placeholder == o.content){
ed.setContent('');
}
});
}
// clear content
这一直有效,直到
我试过了onSubmit
:
ed.onSubmit.add(function(ed, e) {
// replace the content back to empty if the same as placeholder
if(editorMce_placeholder == $(ed.getContent()).text()){
ed.setContent("");
// just to be sure:
$editorMce.val("");
}
});
还有onPostProcess
:
ed.onPostProcess.add(function(ed, e) {
// replace the content back to empty if the same as placeholder
if(editorMce_placeholder == $(ed.getContent()).text()){
o.content = '';
}
});
所有这些都不会在提交时清除 textarea 值/iframe 内容,您不会更改它与占位符值一起保存的值。