开发者

Infinite loop in jQuery

I have a problem with jQuery, for some reason, that code makes inf开发者_JAVA百科inite loop:

$(document).ready(function () {
    function changeURL() {
        location.href = 'http://aaa.com';
    }

    $('#daysLeftSort').change(changeURL());
});


When assigning an event handler, assign the function reference directly, not the result of the function, so leave off the () (which calls the function immediately...reloading the page), like this:

$('#daysLeftSort').change(changeURL);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜