我想知道如何从另一个对象文字中的对象调用方法。这是我的代码。我正在构建一个 jQuery UI 滑块。我正在尝试在动画对象文字中调用animatebox函数,而我的 chrome 控制台中的错误是:
Uncaught TypeError: Cannot call method 'animateBox' of undefined
我的代码如下所示:
var sliderOpts = {
animate: true,
range: "min",
value: 50,
min: 10,
max: 100,
step: 10,
//this gets a live reading of the value and prints it on the page
slide: function (event, ui) {
$("#slider-result").html(ui.value + " GB");
},
//this updates the hidden form field so we can submit the data using a form
change: function (event, ui) {
$('#hidden').attr('value', ui.value);
var val = ui.value,
$box = $('#message');
switch (true) {
case (val > 50):
$box.animations.animateBox().html('you have chosen xtremenet');
break;
case (val < 50):
$box.fadeOut().fadeIn().html('you have chosen valuenet');
break;
default:
$box.fadeOut().fadeIn().html('you have chosen powernet');
}
}
};
var animations = {
animateBox: function () {
$("#message").slideDown(500);
}
};
$(".slider").bind("slidecreate", animations.animateBox).slider(sliderOpts);
那么如何调用这个名为 animateBox 的方法呢?