javascript – 如何在TinyMCE 4中设置内容,最好在$(document).ready()内;块?
作者:互联网
正如标题所说,我抬头看了official documentation,但它没有用;这是我的JavaScript(利用jQuery)代码:
$(document).ready(function() {
tinymce.init({
element_format: "html",
schema: "html4",
menubar: false,
plugins: 'preview textcolor link code',
selector: 'TEXTAREA#rtf',
toolbar: 'preview | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | blockquote subscript superscript | code'
});
tinymce.activeEditor.setContent($('TEXTAREA#rtf').text());
});
>我试图检查tinymce和tinyMCE(得到了这个
谷歌搜索实例,他们都是对象好.
>我还试图检查tinymce.activeEditor和tinyMCE.activeEditor,
但结果却是空的!
(咳嗽)不知何故,在我将所有东西恢复到我现在开始的位置后,它可以工作:
$(document).ready(function() {
tinymce.init({
element_format: "html",
menubar: false,
plugins: 'preview textcolor link code',
schema: "html4",
selector: 'TEXTAREA#rtf',
toolbar: 'preview | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | blockquote subscript superscript | code'
});
});
我怀疑这是由于UA缓存或XSLT转换结果缓存引起的问题;感谢你的宝贵时间!
解决方法:
这就是我实现它的方式:
setTimeout(tinyMCE.init({
selector: "textarea.edit_notes",
height: editor_height,
theme: "modern",
menubar: "tools table format view insert edit",
force_br_newlines : false,
force_p_newlines : false,
forced_root_block : '',
//plugins: "fullpage",
valid_elements : '*[*]',
setup: function(ed){
ed.on("init",
function(ed) {
tinyMCE.get('testeditor').setContent($('#testeditor').val());
tinyMCE.execCommand('mceRepaint');
}
);
}
}), 50);
试一试
标签:tinymce-4,javascript,jquery 来源: https://codeday.me/bug/20191006/1861044.html