我希望我能清楚地解释清楚。
我显示12个字符代表时间
A = 23-1:59 至 L = 21-22:59
每天都有幸运时间,例如今天幸运时间是C,D,E和F那些需要大胆的。
如果今天是幸运时间,角色需要眨眼。
我们每天都会指定幸运时间,并将其存储在excel中。
我使用PHPExcel提取并将其发送到luckyTime()函数
window.setInterval(function(){
luckyTime(<?php echo json_encode($lucky_data); ?>);
}, 1000);
这是我的代码
<span class="cn-time" id="cn-time-1">A</span>
<span class="cn-time" id="cn-time-2">B</span>
<span class="cn-time" id="cn-time-3">C</span>
<span class="cn-time" id="cn-time-4">D</span>
<span class="cn-time" id="cn-time-5">E</span>
<span class="cn-time" id="cn-time-6">F</span>
<span class="cn-time" id="cn-time-7">G</span>
<span class="cn-time" id="cn-time-8">H</span>
<span class="cn-time" id="cn-time-9">I</span>
<span class="cn-time" id="cn-time-10">J</span>
<span class="cn-time" id="cn-time-11">K</span>
<span class="cn-time" id="cn-time-12">L</span>
/* JAVASCRIPT */
function luckyTime(t)
var jArray = t;
var hr = new Date().getHours();
var min = new Date().getMinutes();
$('.cn-time').removeClass("blink");
$('.cn-time').removeClass("lucky-time");
if(jArray[1] == "CHECK") {
$('#cn-time-1').addClass("lucky-time");
if(hr == 23 || hr == 0 || hr == 0 && min < 60) {
$('#cn-time-1').addClass("blink");
}
}
if(jArray[2] == "CHECK") {
$('#cn-time-2').addClass("lucky-time");
if(hr == 1 || hr == 2 || hr == 2 && min < 60) {
$('#cn-time-2').addClass("blink");
}
}
if(jArray[3] == "CHECK") {
$('#cn-time-3').addClass("lucky-time");
if(hr == 3 || hr == 4 || hr == 4 && min < 60) {
$('#cn-time-3').addClass("blink");
}
}
if(jArray[4] == "CHECK") {
$('#cn-time-4').addClass("lucky-time");
if(hr == 5 || hr == 6 || hr == 6 && min < 60) {
$('#cn-time-4').addClass("blink");
}
}
if(jArray[5] == "CHECK") {
$('#cn-time-5').addClass("lucky-time");
if(hr == 7 || hr == 8 || hr == 8 && min < 60) {
$('#cn-time-5').addClass("blink");
}
}
if(jArray[6] == "CHECK") {
$('#cn-time-6').addClass("lucky-time");
if(hr == 9 || hr == 10 || hr == 10 && min < 60) {
$('#cn-time-6').addClass("blink");
}
}
if(jArray[7] == "CHECK") {
$('#cn-time-7').addClass("lucky-time");
if(hr == 11 || hr == 12 || hr == 12 && min < 60) {
$('#cn-time-7').addClass("blink");
}
}
if(jArray[8] == "CHECK") {
$('#cn-time-8').addClass("lucky-time");
if(hr == 13 || hr == 14 || hr == 14 && min < 60) {
$('#cn-time-8').addClass("blink");
}
}
if(jArray[9] == "CHECK") {
$('#cn-time-9').addClass("lucky-time");
if(hr == 15 || hr == 16 || hr == 16 && min < 60) {
$('#cn-time-9').addClass("blink");
}
}
if(jArray[10] == "CHECK") {
$('#cn-time-10').addClass("lucky-time");
if(hr == 17 || hr == 18 || hr == 18 && min < 60) {
$('#cn-time-10').addClass("blink");
}
}
if(jArray[11] == "CHECK") {
$('#cn-time-11').addClass("lucky-time");
if(hr == 19 || hr == 20 || hr == 20 && min < 60) {
$('#cn-time-11').addClass("blink");
}
}
if(jArray[12] == "CHECK") {
$('#cn-time-12').addClass("lucky-time");
if(hr == 21 || hr == 22 || hr == 22 && min < 60) {
$('#cn-time-12').addClass("blink");
}
}
我的问题是,在没有刷新页面的情况下,我无法获得新的幸运时间。
答案 0 :(得分:1)
请在luckyTime函数中添加ajax请求以获取最新数据,并返回json格式的数据:
window.setInterval(function(){
luckyTime();
}, 1000);
function luckyTime(){
$.ajax({
url:"getLatestData.php",
success:function(r){
var jArray = JSON.parse(r);
var hr = new Date().getHours();
var min = new Date().getMinutes();
$('.cn-time').removeClass("blink");
$('.cn-time').removeClass("lucky-time");
if(jArray[1] == "CHECK") {
$('#cn-time-1').addClass("lucky-time");
if(hr == 23 || hr == 0 || hr == 0 && min < 60) {
$('#cn-time-1').addClass("blink");
}
}
if(jArray[2] == "CHECK") {
$('#cn-time-2').addClass("lucky-time");
if(hr == 1 || hr == 2 || hr == 2 && min < 60) {
$('#cn-time-2').addClass("blink");
}
}
if(jArray[3] == "CHECK") {
$('#cn-time-3').addClass("lucky-time");
if(hr == 3 || hr == 4 || hr == 4 && min < 60) {
$('#cn-time-3').addClass("blink");
}
}
if(jArray[4] == "CHECK") {
$('#cn-time-4').addClass("lucky-time");
if(hr == 5 || hr == 6 || hr == 6 && min < 60) {
$('#cn-time-4').addClass("blink");
}
}
if(jArray[5] == "CHECK") {
$('#cn-time-5').addClass("lucky-time");
if(hr == 7 || hr == 8 || hr == 8 && min < 60) {
$('#cn-time-5').addClass("blink");
}
}
if(jArray[6] == "CHECK") {
$('#cn-time-6').addClass("lucky-time");
if(hr == 9 || hr == 10 || hr == 10 && min < 60) {
$('#cn-time-6').addClass("blink");
}
}
if(jArray[7] == "CHECK") {
$('#cn-time-7').addClass("lucky-time");
if(hr == 11 || hr == 12 || hr == 12 && min < 60) {
$('#cn-time-7').addClass("blink");
}
}
if(jArray[8] == "CHECK") {
$('#cn-time-8').addClass("lucky-time");
if(hr == 13 || hr == 14 || hr == 14 && min < 60) {
$('#cn-time-8').addClass("blink");
}
}
if(jArray[9] == "CHECK") {
$('#cn-time-9').addClass("lucky-time");
if(hr == 15 || hr == 16 || hr == 16 && min < 60) {
$('#cn-time-9').addClass("blink");
}
}
if(jArray[10] == "CHECK") {
$('#cn-time-10').addClass("lucky-time");
if(hr == 17 || hr == 18 || hr == 18 && min < 60) {
$('#cn-time-10').addClass("blink");
}
}
if(jArray[11] == "CHECK") {
$('#cn-time-11').addClass("lucky-time");
if(hr == 19 || hr == 20 || hr == 20 && min < 60) {
$('#cn-time-11').addClass("blink");
}
}
if(jArray[12] == "CHECK") {
$('#cn-time-12').addClass("lucky-time");
if(hr == 21 || hr == 22 || hr == 22 && min < 60) {
$('#cn-time-12').addClass("blink");
}
}
}
});
}