开发者

Infinite loop in jQuery

开发者 https://www.devze.com 2023-01-30 17:34 出处:网络
I have a problem with jQuery, for some reason, that code makes inf开发者_JAVA百科inite loop: $(document).ready(function () {

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

精彩评论

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