Trying to get the text written inside a TinyMCE textarea

给你一囗甜甜゛ 提交于 2019-12-05 12:11:54

问题


I'm trying to get the text written inside a TinyMCE textarea. I have the code below. The TinyMCE text area is showed but the alert is not even showed. Why?

<html>
    <head></head>
    <body>
        <script type="text/javascript" src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js'></script> 
        <script type="text/javascript" src="/home/javiergarcia/Scaricati/jari/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
        <script type="text/javascript"> 
            tinyMCE.init({
                mode : "textareas",
            });

            $(document).ready(function() {
                $('form').submit(function() {
                    //alert("fasdfs");
                    alert(tinyMCE.get('#jander').getContent());
                });
            });
        </script>
        <form method="post" action="somepage">
            <textarea name="content" id="jander" style="width:100%"></textarea> 
            <input type="submit">
        </form>
    </body>
</html>

Regards

Javier


回答1:


Why don't you simply use tinymce.get('jander').getContent(); (tinymce in lowercases!) ?




回答2:


You should simply request the value of the original textarea control.

tinyMCE.triggerSave(false, true);
$('#jander').val();



回答3:


Once you've included the TinyMCE jQuery plugin, you assign the editor to a variable and can then operate any jQuery function on it:

var wysiwyg = $('textarea.tinymce').tinymce(tinymce_settings);

Then to get the contents you can just fetch wysiwyg.html();

Also, see the TinyMCE jQuery documentation for other manipulation techniques.




回答4:


As someone told me, the sharp character (#) is used in jQuery selectors and has nothing to do with tinyMCE.get(). So with this line below works ok.

alert(tinyMCE.get('jander').getContent());   



回答5:


try this one....

$.trim(tinymce.get('jander').getContent());



来源:https://stackoverflow.com/questions/5430543/trying-to-get-the-text-written-inside-a-tinymce-textarea

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