使用 JQuery 填充 TinyMCE 文本区域(移动设备)

发布于 2024-12-18 13:34:33 字数 391 浏览 1 评论 0原文

所以我初始化了我的文本区域,现在它是一个 TinyMCE 框......太棒了。

但我希望用户选择一些数据,然后用该数据填充该文本区域(顺便说一句,这是 HTML)...我使用此代码:

 var text = file.rows.item(0).presentData;
    if (text != null) {
        text = text.replace(/\n/g, '<br />');
        $('#editcontent').val(text); 

#editcontent 是一个文本区域...这工作正常,直到我添加 TinyMCE。现在,当我点击此页面时,内容尚未填写。

有什么想法吗?

So I init my textarea and now its a TinyMCE box...great.

But I want the user to choose a some data and then fill in that textarea with that data (which is HTML btw) ... I was using this code:

 var text = file.rows.item(0).presentData;
    if (text != null) {
        text = text.replace(/\n/g, '<br />');
        $('#editcontent').val(text); 

#editcontent being a textarea... this worked fine until I added TinyMCE. Now when I hit this page, the contents are not filled in.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

陪你搞怪i 2024-12-25 13:34:33

正如 Jasper 所说,首先填充文本区域。

TinyMCE 的作用是隐藏文本区域并在其位置放置一个可编辑的 Iframe。

如果您之前无法填充文本区域,则可以使用 firebug 或其他类似的解决方案检查实时代码,以查看 Ifram 获取的名称或 ID,或者您是否可以指定 id。

然后使用它来访问 Iframe。

As Jasper states, fill the textarea first.

What TinyMCE does is hide your textarea and place an editable Iframe in its place.

If you cannot fill the textarea before you might check you live code with firebug or some similar solution to see what the Ifram gets as name or ID or if you can specify an id.

Then use that to access the Iframe instead.

黯然#的苍凉 2024-12-25 13:34:33

试试这个:

var newtext = 'some text';
tinyMCE.get('editcontent').setContent(newtext);

Try this:

var newtext = 'some text';
tinyMCE.get('editcontent').setContent(newtext);
ゃ懵逼小萝莉 2024-12-25 13:34:33

设置文本区域的值后初始化 TinyMCE 实例怎么样?

 var text = file.rows.item(0).presentData;
    if (text != null) {
        text = text.replace(/\n/g, '<br />');
        $('#editcontent').val(text).tinymce(...);

我不确定这是否是初始化 TinyMCE 的方式,但如果您在 $('#editcontent').val(text) 行之后初始化它,那么它应该可以处理您的数据。

您还可以“刷新”TinyMCE 实例的内容。

  1. http://www.tinymce.com/forum/viewtopic.php?id= 25909
  2. 如何刷新 TinyMCE 的代码我用 JavaScript 添加的
  3. 如何刷新tinymce iframe?
  4. http://www.tinymce.com/wiki.php/Command_identifiers< /a>

What about initializing the TinyMCE instance after you have set the value of your textarea?

 var text = file.rows.item(0).presentData;
    if (text != null) {
        text = text.replace(/\n/g, '<br />');
        $('#editcontent').val(text).tinymce(...);

I'm not sure if that's how you initialize TinyMCE but if you initialize it after the $('#editcontent').val(text) line then it should work with your data.

You can also "refresh" the content of your TinyMCE instance.

  1. http://www.tinymce.com/forum/viewtopic.php?id=25909
  2. How do I refresh TinyMCE for the code that I add with JavaScript
  3. How to refresh tinymce iframe?
  4. http://www.tinymce.com/wiki.php/Command_identifiers
め七分饶幸 2024-12-25 13:34:33

我在加载时调用 init ,然后在填写文本后再次尝试执行此操作...最终对我有用的是在填写文本区域框后这样调用它。

 if (text != null) {
    text = text.replace(/\n/g, '<br />');
    $('#editcontent').val(text);     
}
else {
    text = '<div style="margin: 10%"><h2>This is a blank presentation.  Click edit.</h2></div>';
    $('#editcontent').val('');
}

$('textarea#editcontent').tinymce({
    mode : "textareas",
    theme : "advanced",
    plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",

    theme_advanced_buttons1 : "formatselect,bold,italic,underline,strikethrough,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,fontsizeselect,undo,redo,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,charmap",
        theme_advanced_buttons2 : '',
        theme_advanced_buttons3 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "none",
        theme_advanced_resizing : true,
});

I was calling init at the load and then tried to do it again after I filled in the text... what finally worked for me was to call it like that AFTER I filled in my textarea box.

 if (text != null) {
    text = text.replace(/\n/g, '<br />');
    $('#editcontent').val(text);     
}
else {
    text = '<div style="margin: 10%"><h2>This is a blank presentation.  Click edit.</h2></div>';
    $('#editcontent').val('');
}

$('textarea#editcontent').tinymce({
    mode : "textareas",
    theme : "advanced",
    plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",

    theme_advanced_buttons1 : "formatselect,bold,italic,underline,strikethrough,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,fontsizeselect,undo,redo,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,charmap",
        theme_advanced_buttons2 : '',
        theme_advanced_buttons3 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "none",
        theme_advanced_resizing : true,
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文