I am bit stuck, don't know if its开发者_如何学运维 possible to turn:
$("#id").click(function(){
var that = jQuery(this);
wildFunction(that);
});
into
$("#id").click(wildFunction(this));
"this" is a scope variable so it would be present in the event handler no matter how you bind it. so this would work:
$("#id").click(wildFunction);
function wildFunction()
{
var that = $(this); // this is valid here, and we can make jQuery object with it
}
No, you can't do that — or rather, you could, but it wouldn't be useful. You need to have that function syntax there. In your second code sample, this
would be whatever it is in the code calling click
, where I'm assuming from your first code sample you want it to be the this
that jQuery sets up for the event handler.
Nope, but you can use
$("#id").click( wildFunction );
and inside the wildFunction
method this
will refer to the #id
DOM element.
精彩评论