var until = $("#time").html(); function updateTime() { $("#time").html( date("d",until) + " day(s)<br />" + date("h",until) + " hour(s)<br />" + date("i",until) + " minute(s)<br />" + date("s",until) + " second(s)" ); } setInterval("updateTime(until)",1000);
每次我运行这个,我都会收到此错误:
Uncaught ReferenceError: until is not defined
(anonymous function)
我看不出什么是错的.我试图谷歌很多,但我找到的每一页,都说setInterval()是正确的.
解决方法
闭包:
setInterval(function() {updateTime(until); },1000);