gpt4 book ai didi

javascript - jquery/javascript 中未定义的函数

转载 作者:行者123 更新时间:2023-12-02 19:10:27 25 4
gpt4 key购买 nike

zoom: function ( element, scale ){.....},
init: function() {
$("#book div img").live('dblclick', function() {
...
$( "#slider" ).slider({
...
slide: function( event, ui ) {
//call function here
zoom (element,ui.value);
}
});
});
},

有两个功能,缩放和主功能。 main 函数调用了 Zoom 函数来执行工作,但由于不在同一级别,浏览器返回 undefined function 'zoom' 的错误。如何解决这个问题(能够在幻灯片中调用缩放:函数)?

最佳答案

在函数的最外层作用域中存储对 this 对象的引用。然后在回调中调用 this.zoom() :

zoom: function ( element, scale ){.....},
init: function() {
// store a reference to the object these functions are being added to
var that = this;

$("#book div img").live('dblclick', function() {
...
$( "#slider" ).slider({
...
slide: function( event, ui ) {
// use the var you made above to call zoom
that.zoom (element,ui.value);
}
});
});
},

简化示例:http://jsfiddle.net/u5ZL3/

关于javascript - jquery/javascript 中未定义的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13812638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com