本文介绍了使用jQuery选择器获取tinymce textarea的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得一个tinymce textarea的价值

I want to get the value of a tinymce textarea

<textarea id="thetextarea"></textarea>

按下

键以使用以下命令将其输入到放映预览脚本中:

on key up in order to feed it into a show-preview script using:

function showPreview(value) {

    $("#preview-container").load("/material-preview.php", {s:value});

}
$('thetextarea').live("keyup",function (e) {

        var material = this.value;
        showPreview(material);

        return false;

    });

如果我尝试选择textarea id thetextarea,它将不起作用(如果我不将其设置为tinymce字段,则可以使用).

If I try to select the textarea id thetextarea it doesnt work (works if I dont make it an tinymce-field).

使用萤火虫,我看到当textarea转换为textarea时,该文本位于:

with firebug I see that the text, when the textarea is tinymce-converted, is in:

<body id="tinymce" class="mceContentBody"></body>

但是这也不起作用,($('#tinymce')也不行)

but this does not work either, (nor does $('#tinymce'))

 $('mceContentBody').live("keyup",function (e) {

            var material = this.value;
            showPreview(material);

            return false;

        });

根据要求应用tinyMCE之后的HTML代码(来自Firebug)

HTML code (from firebug) after tinyMCE is applied as requested

 <textarea id="material-input" class="mceEditor text" style="width: 310px ! important; height: 250px ! important; display: none;" name="material" aria-hidden="true"></textarea>
      <span id="material-input_parent" class="mceEditor defaultSkin" role="application" aria-labelledby="material-input_voice">
      <span id="material-input_voice" class="mceVoiceLabel" style="display:none;">Rich Text Area</span>
      <table id="material-input_tbl" class="mceLayout" cellspacing="0" cellpadding="0" role="presentation" style="width: 310px; height: 250px;">
        <tbody>
          <tr class="mceFirst" role="presentation">
          <tr>
          <td class="mceIframeContainer mceFirst mceLast">
            <iframe id="material-input_ifr" frameborder="0" src="javascript:""" allowtransparency="true" title="Rich Text Area. Press ALT F10 for toolbar. Press ALT 0 for help." style="width: 100%; height: 206px;">
            <html>
             <head xmlns="http://www.w3.org/1999/xhtml">
               <body id="tinymce" class="mceContentBody " contenteditable="true" spellcheck="false" dir="ltr">
                  <!-- the text inside tinymce textarea -->
                </body>
            </iframe>
           </td>
           </tr>
           <tr class="mceLast">
         </tbody>
       </table>
    </span>

推荐答案

致电

tinyMCE.triggerSave();

之后,您将可以使用jquery选择器

after that you'll be able to use jquery selector

$("#yourtextareaID").val();

这篇关于使用jQuery选择器获取tinymce textarea的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 09:25