【问题标题】:Tinymce how to call init on a new added textarea?Tinymce 如何在新添加的 textarea 上调用 init?
【发布时间】:2014-09-18 20:25:11
【问题描述】:
我正在使用 tinymce,所以我第一次调用
tinymce.init({
// initiation code, that makes my textarea a tinymce textarea
})
在我添加一个新的 textarea 并再次调用 tinymce.init 之后 - 它不起作用。如何将新添加的 textarea 转换为 tinymce textarea?
【问题讨论】:
标签:
javascript
html
tinymce
【解决方案1】:
在 tinymce.init({}); 之后你需要运行这段代码:
tinyMCE.execCommand("mceAddControl", true, textAreaID);
但是它在 Firefox 下不起作用。小修改:
setTimeout( function(){
tinyMCE.execCommand('mceAddControl', true, textAreaID );
}, 100);
Link to this
【解决方案2】:
我认为您不需要为同一页面中的多个 textarea 标签一次又一次地调用 tinymce.init。试试下面的代码,让我知道它有效。
tinymce.init({
selector: "textarea",
// initiation code, that makes my textarea a tinymce textarea
})
它将处理当前页面中遇到的所有 textarea 标签。
【解决方案3】:
试试这个,添加功能
<script>
tinymce.init({
selector: "textarea.tiny-mce-init",
menubar: false,
width: '100%',
height: 200,
resize: false,
plugins: [
"code advlist autolink link image lists charmap print preview hr pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"save table contextmenu directionality emoticons template paste jbimages"
],
toolbar: "code | undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | forecolor backcolor| jbimages | pastetext | fontselect | fontsizeselect | preview ",
// ===========================================
// SET RELATIVE_URLS to FALSE (This is required for images to display properly)
// ===========================================
relative_urls: false
});
</script>
你应该在输入类型 textarea 中调用类
<textarea name="sample" class="tiny-mce-init"></textarea>