Getting value of textarea which is under control of tinymce editor using jquery without sending form

假如想象 提交于 2019-12-09 16:09:49

问题


I have some textarea

<textarea name='text' id='text' ></textarea>

which is under control of tinymce script.

And I have simple javascript

alert ($('#text').val());

which gives me nothing. Problem is that tinymce is converting textarea into something , so actually there is no textarea with id 'text' anymore. Because of that javascript gives empty alerts when I press submit button even if there is some text typed in textarea.

So question is how can javascript get the value of such textarea on the fly whenever I need it ?


回答1:


It should be possible using the get [docs] and getContent [docs] methods:

var value = tinymce.get('text').getContent();



回答2:


There is a method of the TinyMCE instance that can "sync" the TinyMCE content (an IFRAME) with your textarea. I think the method is triggerSave(). Look also here: Need to autosave TinyMCE



来源:https://stackoverflow.com/questions/6830541/getting-value-of-textarea-which-is-under-control-of-tinymce-editor-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!