JS
<?php
date_default_timezone_set('America/Los_Angeles');
$date = date('Gi', time());
?>
<script type="text/javascript">
$(function() {
$(".show_hide").click( function()
{
var locTime = <?php echo json_encode($date) ?>;
$.getJSON( "url_to_json", function(data) {
xr_mon_b_o = data.location.monday[0].b_o;
xr_mon_l_c = data.location.monday[0].l_c;
xr_mon_d_o = data.location.monday[0].d_o;
xr_mon_d_c = data.location.monday[0].d_c;
console.log("sucess1");
if (locTime < xr_mon_b_o){
console.log("sucess2");
$('.xr').hide("drop", { direction: "down" }, 400);
}
else if ( xr_mon_d_o < locTime > xr_mon_l_c){
console.log("sucess4");
$('.xr').hide("drop", { direction: "down" }, 400);
}
else if ( locTime > xr_mon_d_c){
console.log("sucess4");
$('.xr').hide("drop", { direction: "down" }, 400);
}
else {
$('.s_lo').show("drop", {
direction: "up"
}, 800);
}
});
}
);
});
json
{ "location":
{
"monday": [
{"b_o": 700},
{"l_c": 1400},
{"d_o": 1700},
{"d_c": 2100}
]
}
}
b = 早餐
l = 午餐
d = 晚餐
o = 打开
c = 关闭
我正在尝试使此脚本在时间落入 else if 参数的情况下工作,并通过 jquery 操作触发关闭的位置 div 隐藏。但不知何故,这个脚本中的逻辑似乎不能很好地工作。它适用于 1 if,但是当我添加更多“else if”时,脚本会崩溃。