我有一个调用 SwapOnscreenPhotos 的函数。这是该功能的来源:
function SwapOnscreenPhotos(currentPhotoSet, arrowClicked)
{
$("#photo-list img").each(function(index)
{
$(this).attr("src", photoData[currentPhotoSet][index].url);
if (photoData[currentPhotoSet][index].liked === true)
{
$(this).addClass("liked");
}
else
{
$(this).removeClass("liked");
}
});
//Animate the old photos off of the screen
$("#match").hide("slide", { direction: "left" }, 1000);
}
我做了一些随机的事情,然后在函数结束时,我想无条件地调用 #match 上的效果。没有事件之后我要执行此效果(如果重要,事件会确定我是否首先调用 SwapOnScreenPhotos)。我应该如何执行这个效果?
编辑:
对不起,让我澄清一下自己。我的印象是每个 jQuery 表达式都遵循类似的公式。$('selector').event(function() { //function stuff});
我的代码$("#match").hide("slide", { direction: "left" }, 1000);
与这个例子有很大的不同。我的代码更类似于以下模型:$('selector').function
. 请注意,没有任何事件指示我的代码应该何时执行以及何时不应执行。有没有办法在没有这个事件的情况下调用 jQuery 函数?当我尝试运行上面的代码时,我得到了这个错误:
未捕获的类型错误:对象 # 的属性 '#' 不是函数 jquery.js:8780 Tween.run jquery.js:8780 tick jquery.js:8491 jQuery.fx.timer jquery.js:9032 Animation jquery.js:8555 jQuery .fn.extend.animate.doAnimation jquery.js:8871 jQuery.extend.dequeue jquery.js:1894 jQuery.fn.extend.queue jquery.js:1937 jQuery.extend.each jquery.js:611 jQuery.fn.jQuery .each jquery.js:241 jQuery.fn.extend.queue jquery.js:1930 jQuery.fn.extend.animate jquery.js:8881 jQuery.each.jQuery.fn.(匿名函数) jquery.js:8853 AnimateMatch 匹配.js:21 SwapOnscreenPhotos match.js:70 $.ajax.success match.js:167 jQuery.Callbacks.fire jquery.js:974 jQuery.Callbacks.self.fireWith jquery.js:1082 done jquery.js:7650 jQuery. ajaxTransport.send.callback
我认为此错误是由于我未能指定事件引起的。这更有意义吗?谢谢