setInterval()不起作用
setInterval() not working
本文关键字:不起作用 setInterval 更新时间:2023-09-26
我试图在"1秒"的setInterval()
运行一个函数,但这有点问题。我已经做了这里所示的一切,但它不工作。
<script>
function test(db_time)
{
var c_db_time= db_time/1000;
var current_time = new Date().getTime()/1000;
return Math.round(current_time - c_db_time);
}
$(".elapsed_time").each(function() {
var time_r = $(this).data('time_raw');
var inter = $(this).html(time_ago(time_r));//parameter to function
setInterval(inter,1000)
});
</script>
Uncaught SyntaxError: Unexpected identifier
解决方案找到感谢@Bommox &@Satpal
$(".elapsed_time").each(function() {
var time_r = $(this).data('time_raw');
var self = $(this);
var inter = function() {self.html(time_ago(time_r));}
setInterval(inter, 1000);
});
到setInterval
函数的第一个参数中,你应该传递一个函数或一个匿名函数,如
setInterval(function(){
console.log("1s delayed")
},1000);
如前所述,第一个参数应该是函数:
var self = $(this);
var inter = function() {
self.html(time_ago(time_r));
}
setInterval(inter, 1000);
var self = this;
setInterval(function(){
$(self).html(time_ago(time_r));
},1000);
看这里:window.setInterval
window.setTimeout( function() { /*your code which you want to execute after fixed interval, it can function name or lines of code*/}, /*fixedInterval*/);
window.setTimeout( function() { alert("Hello World!"); }, 5000); // it will execute after 5 seconds
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 监视函数从服务返回不起作用,但作用域函数起作用
- 幻灯片滚动javascript不起作用
- 简单的javascript在Shopify中不起作用
- Recaptcha在IE7和IE8中不起作用
- Ember Data DS.Model's set函数不起作用
- JsFiddle上的鼠标事件不起作用
- 我的AngularJS表达式没有'不起作用
- 点击按钮输入不起作用
- 面向对象的Javascript代码在IE7中不起作用
- 分部隐藏在jquery中不起作用
- 在phonegap应用程序内部重定向不起作用
- Array.length似乎不起作用;console.log则显示其他情况
- $ionicplatform内的$scope不;不起作用
- 我的javascript for循环不起作用
- Meteor-添加用户自定义字段的方法不起作用
- 为什么 .focus() 不起作用,而 .css(“color”,“red”) 在同一个选择器上起作用
- Textarea必需的attribut在javascript中不起作用
- 为什么javascript:void(0)在Firefox中不起作用
- 退出全屏不起作用