开发者

Using a function

开发者 https://www.devze.com 2023-04-05 20:41 出处:网络
Hey wasn\'t sure how to explain or ask this question so I\'ll demonstrate with code, say I have this:

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

精彩评论

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