Jos*_*eph 25 tinymce jquery-selectors
我想得到一个tinymce textarea的价值
<textarea id="thetextarea"></textarea>
Run Code Online (Sandbox Code Playgroud)
在键上以便使用以下内容将其提供给show-preview脚本:
function showPreview(value) {
$("#preview-container").load("/material-preview.php", {s:value});
}
$('thetextarea').live("keyup",function (e) {
var material = this.value;
showPreview(material);
return false;
});
Run Code Online (Sandbox Code Playgroud)
如果我尝试选择textarea id thetextarea它不起作用(如果我不使它成为一个tinymce字段,则有效).
与firebug我看到文本,当textarea被tinymce转换,是在:
<body id="tinymce" class="mceContentBody"></body>
Run Code Online (Sandbox Code Playgroud)
但这也不起作用,(也没有$('#tinymce'))
$('mceContentBody').live("keyup",function (e) {
var material = this.value;
showPreview(material);
return false;
});
Run Code Online (Sandbox Code Playgroud)
在按要求应用tinyMCE之后的HTML代码(来自firebug)
<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>
Run Code Online (Sandbox Code Playgroud)
小智 62
呼叫
tinyMCE.triggerSave();
Run Code Online (Sandbox Code Playgroud)
之后,您将能够使用jquery选择器
$("#yourtextareaID").val();
Run Code Online (Sandbox Code Playgroud)
在上面的例子中你的选择器是错误的。它应该是:
$('#thetextarea').live("keyup",function (e) {
Run Code Online (Sandbox Code Playgroud)
不是
$('thetextarea').live("keyup",function (e) {
Run Code Online (Sandbox Code Playgroud)
这只是您问题中的拼写错误吗?
如果您不确定哪个元素具有所需的文本,您可以尝试将事件处理程序添加到这两个元素。另外我认为你应该使用$(this).val()vs. this.val:
$('#thetextarea, .mceContentBody').live("keyup",function (e) {
var material = $(this).val();
showPreview(material);
return false;
});
Run Code Online (Sandbox Code Playgroud)