1.等待所有图片加载
var imgObjs = [], count = 0; rotate.prizeTotal = prizes.length;//图片总数 var timer = setInterval(function() { if (count == rotate.prizeTotal ) { clearInterval(timer); //加载后执行的回调函数 } }, 50); for(var i = 0;i < prizes.length; i++){ var img = new Image(); img.src = prizes[i].prize_icon; //prizes数组的prize_icon存放图片的地址 imgObjs.push(img); img.onload = function(){ count++; } }
2.js获取服务器时间
var timstamp = new Date().valueOf(); var systemTime = new Date($.ajax({url:"?t="+timstamp,async: false}).getResponseHeader("Date")); return systemTime.valueOf();
3.获取当前时间yyyymmdd格式
//获取当前时间yyyymmdd格式 var CurrentDate = ""; var day = new Date(); var Year = day.getFullYear(); var Month = day.getMonth()+1; var Day = day.getDate(); CurrentDate += Year; if (Month >= 10 ){ CurrentDate += Month; } else{ CurrentDate += "0" + Month; } if (Day >= 10 ){ CurrentDate += Day ; } else{ CurrentDate += "0" + Day ; }
另外Date.parse(new Date())可转化为13位数字形式。