[英]How to put a timestamp within a variable name in javascript (e.g. var a12439853 = 1)
I have made a CSS3 ajax loader using this code. 我已经使用此代码制作了CSS3 ajax加载器。 id is the location of the ajaxloader. id是ajaxloader的位置。 This code works fine and the loader functions properly, however if the function is called twice, the Timeout's will cancel each other out because the timeout is assigned to a variable. 该代码可以正常工作,并且加载程序可以正常运行,但是,如果两次调用该函数,则超时将互相抵消,因为超时已分配给变量。 Somehow, I want to make sure that this will never happen. 我想以某种方式确保这种情况永远不会发生。 Here is the javascript I am using 这是我正在使用的javascript
function ajaxloader(id) {
var i = $("#" + id + " .ajaxpieces").length;
var s = $("#" + id + " .ajaxpieces").filter(function() {
return ($(this).css('background-color') == "rgb(0, 128, 0)");
}).next();
if (s.length < 1) {
s = $("#" + id + " .ajaxpieces").first();
}
s.css('backgroundColor','green').siblings().css('backgroundColor','grey');
ajax_ii = setTimeout(function(){ajaxloader(id);},550);
}
function killloader() {
clearTimeout(ajax_ii);
}
Since every variable are object of window, you can do it this way: 由于每个变量都是window的对象,因此您可以按照以下方式进行操作:
window['a_time'+new Date().getTime()] = setTimeout(function(){
ajaxloader(id);
},550);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.