显示TinyMCE的textarea的动态 [英] Display tinymce textarea dynamically
问题描述
我有一个下拉列表,当做出一个选择后会形式使用Ajax的DOM中插入一堆元素,在这种形式我有,我希望是TinyMCE的文本域文本域。
I have a drop down list that when a selection is made will insert a bunch of elements within a form to the DOM using ajax, within this form I have textareas that I wish to be TinyMCE textareas.
我有我的HTML头这里面的:
I have this inside of my HTML head:
<script type="text/javascript">
tinymce.init({
selector: "textarea"
});
</script>
这是我用添加了一堆元素的AJAX功能,这是工作,我怎么需要它。
This is the ajax function that I use to add a bunch of elements, this is working how I need it to.
function getSecFacility(facsecid, facid) {
$("#new_section_form").hide();
$.ajax({
type: "POST",
url: "facility_section_information.php",
data: 'facility_section_id='+facsecid+'&facility_id='+facid,
success: function(data){
$("#selected_fac_section").html(data);
}
});
//loadTinyMCEEditor();
};
我有没有被阿贾克斯插在我的网页文本域等,它们显示为WYSIWYG编辑器没有问题,当我在新的元素加入我的问题。
I have other textareas on my page that are not inserted by ajax and they display as WYSIWYG editors no problem, the issue is when I am adding in new elements.
我已经检查了其他几个问题,试图找到一个答案,但没有什么工作。
I have checked several other questions trying to find an "answer" but nothing is working.
我试图让一个调用的函数 loadTinyMCEEditor()
,我是我的 getSecFacility()
函数中后调用我的ajax调用。在这个函数中,我试图重新初始化TinyMCE的这些新添加的文字区域。
I tried to make a function called loadTinyMCEEditor()
that I was calling within my getSecFacility()
function after my ajax call. Within this function I was trying to reinitialize tinyMCE for these newly added textareas.
loadTinyMCEEditor()
是这样的:
function loadTinyMCEEditor() {
tinyMCE.init({
selector: "textarea"
});
tinyMCE.execCommand('mceAddControl', false, 'test'); //test is the class name I gave this textarea
//tinyMCE.execCommand('mceAddControl', true, 'test'); //tried setting the bool to true..even tried without these lines
}
无论我怎么努力,我似乎无法得到它与新插入的文本域的工作,我怎样才能让这些文字区域是TinyMCE的文本域?
No matter what I try I cannot seem to get it to work with newly inserted textareas, How can I get these textareas to be TinyMCE textareas?
修改
我现在可以查看编辑给我的新添加的文字区域我做出的选择从我的下拉列表后。然而,这仅运行一次,如果我做的第二选择新的textareas只显示为纯文本域。以下是我在阿贾克斯的功能改变:
I can now view the editor to my newly added textareas after I make a selection from my drop down list. However this only works once, if I make a second selection the new textareas only display as plain textareas. Here is what I changed in my ajax function:
function getFacSecFacility(facsecid, facid) {
$("#new_section_form").hide();
$.ajax({
type: "POST",
url: "facility_section_information.php",
data: 'facility_section_id='+facsecid+'&facility_id='+facid,
success: function(data){
$("#selected_fac_section").html(data);
loadTinyMCEEditor();
}
});
};
function loadTinyMCEEditor() {
tinymce.init({
selector: "textarea"
});
}
于是我做出选择这个AJAX功能将运行并显示新的文字区域+其他形式的信息和我重新初始化TinyMCE的编辑器,但由于某种原因,这只是一次工作后。
So after I make a selection this ajax function will run and display new textareas + other form information and I re-initialize the tinymce editors but for some reason this is only working once.
我应该怎么改/做,这样我可以多选择从我的下拉列表中,这样每次新的文本域将显示为TinyMCE的文本域?
What should I change/do so that I can make multiple selection from my drop down list so that each time the new textareas will display as tinymce textareas?
推荐答案
您需要调用 tinyMCE.activeEditor.setContent
与您输入的Ajax的内容。在你的回调尝试:
You need to call tinyMCE.activeEditor.setContent
with your incoming ajax-content. In your callback try:
tinyMCE.activeEditor.setContent(data);
问候
这篇关于显示TinyMCE的textarea的动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!