Cam*_*tin 14 javascript asynchronous google-chrome setinterval google-chrome-extension
就像标题所说的那样:setInterval
只会触发一次回调.
manifest.json的:
{
//...
"content_scripts" : [{
"js" : ["code.js"],
//...
}],
//...
}
Run Code Online (Sandbox Code Playgroud)
code.js(示例):
setInterval(alert('only shown once'),2000);
Run Code Online (Sandbox Code Playgroud)
为什么,以及我如何解决它?代码在扩展之外(甚至在小书签中)也能很好地工作.
qwe*_*ymk 33
setInterval(function() { alert('only shown once') },2000);
Run Code Online (Sandbox Code Playgroud)
您需要传递函数引用,alert
而不是返回值alert()
setInterval
根本不工作.
第一个参数应该是一个函数,你传递的返回值alert()
不是函数.
使用三个参数版本:
setInterval(function,time,array_of_arguments_to_call_function_with);
setInterval(alert,2000,['only shown once']);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
24335 次 |
最近记录: |