开发者

Using a function

Hey wasn't sure how to explain or ask this question so I'll demonstrate with code, say I have this:

$(function() {

    $(window).resize(foo());

    function foo() {
        alert('bar');
    }

});

How do I make that work inst开发者_JAVA百科ead of doing this:

$(window).resize(function() {
    foo();
});


$(function() {

  $(window).resize(foo);


});


function foo() {
    alert('bar');
}

You basically need to pass the function pointer to jquery.. when you do function(){foo();} you are creating an anonymous function.

Live Demo

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜