基於此代碼:http://codepen.io/anon/pen/VaGdBK 我嘗試顯示商店的營業時間。任何人都可以幫助我使用什麼代碼,以便系統在週日將其狀態更改爲關閉時識別出來?週六和週三的工作時間爲:9:00-16:00。如何在星期天隱藏div(javascript上的開放時間)
var da = new Date();
document.getElementById("display").innerHTML = da.toDateString();
var d = new Date();
var n = d.getDay();
//gets the current time.
//var d = new Date();
var x = document.getElementsByClassName("start")[0].innerText;
var z = document.getElementsByClassName("end")[0].innerText;
//var o = parseInt(x,10);
//var c = parseInt(z,10);
var startTime = Date.parseExact(x, "h:mm tt");
var endTime = Date.parseExact(z, "h:mm tt");
if (da.between(startTime, endTime)){
$(".open").show();
$(".closed").hide();
}
else if (d.getDay = 0){
\t $(".closed").show();
$(".open").hide();
}
else {
$(".closed").show();
$(".open").hide();
}
body{
\t padding:30%;
\t background:pink;
\t color: black;
}
.open, .closed {
display: none;
}
<span style="display:none;"><span class="day"> Monday</span>
<span class="start">8:30 am</span> -
<span class="end">5:30 pm</span>
<br>
<span id="display"></span>
</span>
<div class="open">Shop is open</div>
<div class="closed">Shop is closed</div>
<script>
var da = new Date();
document.getElementById("display").innerHTML = da.toDateString();
//gets the current time.
//var d = new Date();
var x = document.getElementsByClassName("start")[0].innerText;
var z = document.getElementsByClassName("end")[0].innerText;
//var o = parseInt(x,10);
//var c = parseInt(z,10);
var startTime = Date.parseExact(x, "h:mm tt");
var endTime = Date.parseExact(z, "h:mm tt");
if (da.between(startTime, endTime)){
$(".open").show();
$(".closed").hide();
}
else {
$(".closed").show();
$(".open").hide();
}
// how can I show the closed class on Sunday?
// How can I show the open class from 9:00 am to 19:00 pm?
</script>
哪裏php的標籤貼合在? –
也許有另外一種方法,用php –
'else if(d.getDay = 0)'這可能永遠不會運行。 – Nonemoticoner