将时间间隔设置为指定值
set time interval as a specified value
我想将给定函数的时间间隔设置为变量值 timeInMilliseconds..
但得到未定义的错误..请帮我解决这个问题。
提前谢谢你。
window.setInterval(function(){
chrome.storage.local.get("user_inactive_mode", function (obj) {
inactiveStatusMode = obj.user_inactive_mode;
if(inactiveStatusMode == 'true') {
chrome.storage.local.get("user_inactive_time", function (obj) {
var timeInMinuts = obj.user_inactive_time;
var timeInMilliseconds = timeInMinuts * 10;
console.log(timeInMilliseconds);
chrome.idle.queryState(timeInMilliseconds, function (state) {
if (state != "active") {
====
====
=====
}
});
});
}
});
} , timeInMilliseconds);
在函数外初始化变量timeInMillisecond。
之所以说未定义,是因为它超出了范围
var timeInMilliseconds;
window.setInterval(function(){
chrome.storage.local.get("user_inactive_mode", function (obj) {
inactiveStatusMode = obj.user_inactive_mode;
if(inactiveStatusMode == 'true') {
chrome.storage.local.get("user_inactive_time", function (obj) {
var timeInMinuts = obj.user_inactive_time;
timeInMilliseconds = timeInMinuts * 10;
console.log(timeInMilliseconds);
chrome.idle.queryState(timeInMilliseconds, function (state) {
if (state != "active") {
====
====
=====
}
});
});
}
});
} , timeInMilliseconds);
您可以在此处阅读有关 JS 范围的信息:What is the scope of variables in JavaScript?
我想将给定函数的时间间隔设置为变量值 timeInMilliseconds.. 但得到未定义的错误..请帮我解决这个问题。 提前谢谢你。
window.setInterval(function(){
chrome.storage.local.get("user_inactive_mode", function (obj) {
inactiveStatusMode = obj.user_inactive_mode;
if(inactiveStatusMode == 'true') {
chrome.storage.local.get("user_inactive_time", function (obj) {
var timeInMinuts = obj.user_inactive_time;
var timeInMilliseconds = timeInMinuts * 10;
console.log(timeInMilliseconds);
chrome.idle.queryState(timeInMilliseconds, function (state) {
if (state != "active") {
====
====
=====
}
});
});
}
});
} , timeInMilliseconds);
在函数外初始化变量timeInMillisecond。 之所以说未定义,是因为它超出了范围
var timeInMilliseconds;
window.setInterval(function(){
chrome.storage.local.get("user_inactive_mode", function (obj) {
inactiveStatusMode = obj.user_inactive_mode;
if(inactiveStatusMode == 'true') {
chrome.storage.local.get("user_inactive_time", function (obj) {
var timeInMinuts = obj.user_inactive_time;
timeInMilliseconds = timeInMinuts * 10;
console.log(timeInMilliseconds);
chrome.idle.queryState(timeInMilliseconds, function (state) {
if (state != "active") {
====
====
=====
}
});
});
}
});
} , timeInMilliseconds);
您可以在此处阅读有关 JS 范围的信息:What is the scope of variables in JavaScript?