jQuery 中的无限循环
我对 jQuery 有疑问,由于某种原因,该代码会无限循环:
$(document).ready(function () {
function changeURL() {
location.href = 'http://aaa.com';
}
$('#daysLeftSort').change(changeURL());
});
I have a problem with jQuery, for some reason, that code makes infinite loop:
$(document).ready(function () {
function changeURL() {
location.href = 'http://aaa.com';
}
$('#daysLeftSort').change(changeURL());
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
分配事件处理程序时,请直接分配函数引用,而不是函数的结果,因此省略
()
(它调用立即运行...重新加载页面),如下所示: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: