开发者

Why .load is binding event?

I'm doing this:

return this.each(function(){
    $.this.load('searchInterface.html',function(){
        console.log('load');
        //a lot of code
    });
    $('#more_button').bind('click',more());

    function more(){
        console.log('more');
    }
});

And my console is showing:

more

load

That means that somewhere inside .load(), something is clicking on my button. How can I avoid this be开发者_StackOverflow中文版havior?

Thanks!


Declare more above the line that reads $('#more_button').bind('click',more()); and remove the parentheses.

You should be referencing the function, not invoking it.

$('#more_button').bind('click',more);


You are calling the more function. Use:

function more(){
    console.log('more');
}

$('#more_button').bind('click',more);


By including the parentheses, you are calling the more() function rather than passing the reference to id.

Use this instead

$('#more_button').bind('click',more);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜