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);
加载中,请稍侯......
精彩评论