通过JQuery加载TinyMCE之后添加按钮,但无法正常工作 [英] Add a button after loading TinyMCE via JQuery and it's not working
问题描述
我正在通过JQuery加载TinyMCE,并且在加载之后,我想向其中添加一个保存按钮.保存按钮正在调用一个函数,但是Firebug说该函数未定义,在这种情况下,destroyTinyMCE()未定义.怎么了?
I'm loading TinyMCE via JQuery and after it's loaded, I'd like to add a save button to it. The save button is calling a function but Firebug says the function is not defined, in this case destroyTinyMCE() is not defined. What's wrong?
$('div#introText').click(function() {
loadTinyMCE();
$('div#introText').after('<input value="Save" onclick="destroyTinyMCE();" type="button">');
});
function loadTinyMCE() {
//some variable
}
function destroyTinyMCE() {
$('div#introText').tinymce().destroy();
$('div#introText').tinymce().remove();
}
推荐答案
如果该函数位于您的document.ready
处理函数中,则该destroyTinyMCE
函数仅作用于该函数,并且在全局名称空间中查找时(例如onclick="destroyTinyMCE();"
可以),它将不会在那里.而是在创建点击处理程序时附加它,如下所示:
If this is inside your document.ready
handler, then that destroyTinyMCE
function is scoped only to it, and when looking for it in the global namespace (as onclick="destroyTinyMCE();"
will do), it won't be there. Instead attach the click handler when creating it, like this:
$('<input value="Save" type="button">').click(destroyTinyMCE)
.insertAfter('div#introText');
这将正确引用该函数,并且仍然可以将其隐藏在您当前所在的任何闭包内.
This will reference the function correctly and it can still be tucked away inside whatever closure you're in currently.
这篇关于通过JQuery加载TinyMCE之后添加按钮,但无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!