Javascript 试图将文本写入 TinyMCE 文本区域

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5430543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 17:10:17  来源:igfitidea点击:

Trying to get the text written inside a TinyMCE textarea

javascriptjqueryhtmltinymcewysiwyg

提问by ziiweb

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

我正在尝试将文本写入TinyMCEtextarea。我有下面的代码。显示了 TinyMCE 文本区域,但甚至没有显示警报。为什么?

<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

哈维尔

回答by Thariama

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

为什么不简单地使用tinymce.get('jander').getContent();(tinymce in smallcases!) ?

回答by Brian Scott

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

您应该简单地请求原始 textarea 控件的值。

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

回答by Dunhamzzz

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

一旦你包含了 TinyMCE jQuery 插件,你就可以将编辑器分配给一个变量,然后可以在它上面操作任何 jQuery 函数:

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

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

然后要获取您可以获取的内容 wysiwyg.html();

Also, see the TinyMCE jQuery documentationfor other manipulation techniques.

另外,请参阅TinyMCE jQuery 文档以了解其他操作技术。

回答by ziiweb

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.

有人告诉我,尖锐字符 (#) 用于 jQuery 选择器,与 tinyMCE.get() 无关。所以下面的这一行工作正常。

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

回答by Anugrah

try this one....

试试这个....

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

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