在jQuery中将函数作为参数传递?

the*_*edp 7 javascript parameters jquery anonymous function

我想传递给jQuery函数一个常规函数,而不是通常的匿名函数,但我不确定如何做这样的事情.

而不是这个:

function setVersion(feature) {
      $.post("some.php", { abc:"abc" },
      function(data){
         // do something here
      }, "json");
}
Run Code Online (Sandbox Code Playgroud)

我想这样做:

function foo(data){
   // do something here
}

function setVersion(feature) {
      $.post("some.php", { abc:"abc" }, foo, "json");
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

eli*_*ias 12

是的,已经有效了.但是你想它可能看起来像这样:

function setVersion(feature, myFunction) {
      $.post("some.php", { abc:"abc" }, myFunction, "json");
}
setVersion(blah, foo);
Run Code Online (Sandbox Code Playgroud)