0
我似乎無法訪問在點擊事件中創建的插件函數。 創建插件後,我創建另一個按鈕,通常會使用插件的外部功能,但似乎沒有辦法來解決功能。 當在document.ready事件中創建插件時,我沒有訪問該函數的問題。在事件內部創建插件時無法訪問jquery插件的外部函數
任何想法?
var pluginHolder = $('<div/>'); //just in case this was the issue
$("body").on("click","#profile_plugin",function(e)
{
pluginHolder = $('<div/>',{id:"coverCanvas"}); //Holding external button and plugin in a div
abutton = $('<button/>',{class:"buttonis"});
plugin = $('<div/>');
plugin.testClass({
c1:2,
c2:"ffffff",
c3:940,
});
//works fine (plugin renders and fully functional)
plugin.appendTo(pluginHolder);
abutton.appendTo(pluginHolder);
pluginHolder.appendTo($(".container"); //Works
console.log(plugin.testoutput()); //Uncaught TypeError: undefined is not a function
abutton.on("click",doStuff);
function doStuff(e)
{
console.log(plugin.testoutput()); //Uncaught TypeError: undefined is not a function
console.log(plugin[0].testoutput()); //Uncaught TypeError: undefined is not a function
}
});
您的代碼中沒有函數'testoutput'。 – 2014-11-21 21:23:55
是的。我沒有在代碼中包含原型函數。 TestOutput()是原型類對象「TestClass」的測試函數, – skoumas 2014-11-25 11:29:59