开发者

jquery bind stoppropagation callback context

开发者 https://www.devze.com 2023-04-06 23:50 出处:网络
I am trying to prevent multiple events firing. I\'m using a callback fu开发者_JS百科nction to pass an object, like this:

I am trying to prevent multiple events firing.

I'm using a callback fu开发者_JS百科nction to pass an object, like this:

function init() {

    var myObj = this.someObject;

    $('#id').bind("blur keyup change", function (e, obj) {
        return function () {
            SomeFunction(e, obj);
        }
    } (this, myObj));

}

function SomeFunction(e, obj) {
    e.stopPropagation();
    //do something with the object
}

The error is that it can't find the function stopPropagation.

This is because I am assigning 'this' to e in the calling function.

How can I get access to the 'event' in SomeFunction?


I think you'll want to do something like this: http://jsfiddle.net/W47Ky/

0

精彩评论

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