1

完成 jquery ui switchclass 效果后,我在运行函数时遇到问题。

查看它描述的手册

.switchClass( removeClassName, addClassName [, duration ] [, easing ] [, complete ] )

但是当尝试运行时:

$("#main").switchClass('primary','secondary','slow',runAfterComplete());

function runAfterComplete(){
    console.log("switchclass completed");
}

它在完成之前运行它。

4

2 回答 2

2

您需要将函数引用(runAfterComplete)作为回调传递,在您的情况下,您正在调用(()最后)runAfterComplete函数和从它返回的值(undefined)作为switchClass方法的回调

$("#main").switchClass('primary','secondary','slow',runAfterComplete);
于 2013-10-10T10:11:14.503 回答
-2
$("#main").switchClass('primary','secondary','slow', function() {console.log("switchclass completed");});
于 2016-10-10T14:58:27.977 回答