开发者

Need Help Converting JQuery .delegate to .live

I am working on script where I have code like this...

$(document).delegate(scroll.links,'c开发者_如何学编程lick',function(){
            switchTo(getId(this.href))
            return false
        })

I want to convert it into .live I tried but couldnt get it right.

Can anybody show me ?

Thanks.


You can do it this way:

$('scroll.links').live('click', function(){
   switchTo(getId(this.href));
   return false;
});

However, it is important to know the difference between the two:

  • Difference between delegate and live


From reading the docs, I imagine it would be something like this:

$(scroll.links).live("click", function() {
    switchTo(getId(this.href))
    return false
})

Note: I have not tested this. I successfully use delegate() in some of my own code; the docs suggest that delegate() is actually more powerful and more flexible.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜