使用jQuery replaceWith()使用TinyMCE将div更改为textarea(Change div to textarea with TinyMCE using jQuery repl

编程入门 行业动态 更新时间:2024-10-04 17:20:19
使用jQuery replaceWith()使用TinyMCE将div更改为textarea(Change div to textarea with TinyMCE using jQuery replaceWith())

我想用tinyMCE编辑器使用jQuery replaceWith()更改一些文本,这对于replaceWith()函数本身没有问题,但我不知道如何将tinyMCE编辑器实现到新的textarea。

<div id="div">Some text</div>

单击编辑按钮时,将更改为

<textarea id="new">Some text</textarea> (with tinyMCE editor)

我试过两种方法,

1.更换前初始化选择器 - 不工作

tinymce.init({ selector: "#input_insertComment",

2. - 使用tinymce实例(?) - 不工作

$('#div').replaceWith("<textarea id=new>some text</textarea>"); tinymce.initMCEexact("#new");

编辑器都没有实现。 我怎样才能做到这一点?

(在同一页面上,我有另一个文本区域的tinymce编辑器。)

I want to change some text with tinyMCE editor using jQuery replaceWith(), It's no problem with replaceWith() function itself, but I don't know how to implement tinyMCE editor to new textarea.

<div id="div">Some text</div>

When edit button clicked, will change to

<textarea id="new">Some text</textarea> (with tinyMCE editor)

I tried 2 ways,

1. Init tinymce selector before replacing - not working

tinymce.init({ selector: "#input_insertComment",

2. - useing tinymce instance(?) - not working

$('#div').replaceWith("<textarea id=new>some text</textarea>"); tinymce.initMCEexact("#new");

Both the editor aren't implemented. How can I do that?

(At the same page, I have tinymce editor for another textarea.)

最满意答案

当你调用tinymce.init()它只会在你调用init()时影响DOM中存在的项目。 如果您稍后向页面添加元素,则init()调用将不会用TinyMCE替换它们。

你想要的顺序是......

将textarea添加到DOM 调用tinymce.init()并使用init中的selector选项来定位刚刚添加到页面的textarea。

我不知道tinymce.initMCEexact()是一个真正的API调用,它曾经是TinyMCE的一部分 - 它肯定不是TinyMCE 4的一部分。

When you call tinymce.init() it will only impact items that exist in the DOM when you call init(). If you are adding elements to the page later the init() call won't then replace them with TinyMCE.

The sequence you want is...

Add the textarea to the DOM Call tinymce.init() and use the selector option in the init to target the textarea that you just added to the page.

I am not aware of tinymce.initMCEexact() as an actual API call that was ever part of TinyMCE - its not part of TinyMCE 4 for sure.

更多推荐

本文发布于:2023-08-07 12:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464089.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:TinyMCE   replaceWith   jQuery   Change   textarea

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!