开发者

jquery delegate passing variable

I want to pass the object of being clicked into the handler. like this:

$selector.dele开发者_StackOverflow社区gate('.test','click',func1( ?? ));

//this is a reusable function
function func1(obj){
    //do something with obj  .....
}

so in this case, I should pass $('.test') into the function. can anybody give me a hand here, thanks a lot.


Try this

$selector.delegate('.test','click', function(e){
var obj =  this;
//obj will point to the element you clicked.
});


Use $(this) inside func1. this will be the object on which the event occurred.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜