[英]Multiple tinyMCE getContent() fails
I have multiple tinyMCE4 textareas on mye page, which I (all at once) initialize like this: 我的Mye页面上有多个tinyMCE4 textareas,我(一次全部)初始化为:
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
<script>
tinymce.init({
selector: 'textarea',
/* ... more options ..*/
});
</script>
<script src="js/myScript.js"></script>
In myScript.js
I'd like to get the content of each one of the textareas, which look like this: 在
myScript.js
我想获取每个文本区域的内容,如下所示:
<textarea id="editor_1" data-field="1" class="editor"></textarea>
<textarea id="editor_2" data-field="2" class="editor"></textarea>
etc...
I tried this with this (on button click): 我对此进行了尝试(单击按钮时):
$(document).on('click','.saveStandardDoc',function(){
$('.editor').each(function(i, obj) {
var $that = $(this);
console.log(tinyMCE.get($that).getContent());
});
});
Now it gives me tinyMCE.get is not a function
(does not matter if tinymce
or tinyMCE
) 现在它给了我
tinyMCE.get is not a function
( tinymce
或tinyMCE
都没有关系)
Where am I wrong? 我哪里错了?
The get()
method expects the passed parameter to be a String
that contains the id
of the <textarea>
that was replaced with TinyMCE. get()
方法期望传递的参数是一个String
,其中包含用TinyMCE替换的<textarea>
的id
。
In your code you are passing a jQuery reference to the get()
method and that won't work. 在您的代码中,您传递了对
get()
方法的jQuery引用,但该引用不起作用。
https://www.tinymce.com/docs/api/tinymce/root_tinymce/#get https://www.tinymce.com/docs/api/tinymce/root_tinymce/#get
A valid example would be: 一个有效的例子是:
tinymce.get('myEditor')
(note you don't pass a #
at the beginning - its not looking for a CSS selector) (请注意,您在开始时没有传递
#
-它不是在寻找CSS选择器)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.