我對JavaScript很新穎,但正嘗試根據一天中的時間進行文本更改,並根據當天顯示不同的文本。根據當天的日期和時間每天更改文本
目前,我想搞清楚如何每天顯示不同的文本。例如從星期一到星期四,而不是說結束,它會說我們在下午6點開放,並在星期五&星期六,它會說我們是在上午11點開放。
有什麼想法?由於
HTML:
<div class="time"><a href="#contact">
<img id="clock" src="assets/clock.png">
<div id="open_close"></div></a>
</div>
的JavaScript:
var data = [
{},
{open:18, close:22},
{open:18, close:22},
{open:18, close:22},
{open:12, close:22},
{open:12, close:22},
{open:12, close:22}
];
var date = new Date();
var dayOfWeek = date.getDay(); // 0 is Sunday, 1 is Monday, etc...
var openingTimes = data[dayOfWeek];
var openClosed = false; // closed by default
// check that there are opening times for today
if (openingTimes.hasOwnProperty('open') && openingTimes.hasOwnProperty('close')){
var hour = date.getHours()
openClosed = openingTimes.open <= hour && hour < openingTimes.close;
}
$("#open_close").html(
if (openClosed == True){
console.log("we are open now")
}
if else (
0 = 'we are open from mon to Mon to Mon-Sat':
1 = '6pm':
2 = '6pm':
3 = '6pm':
4 = '12pm':
5 = '12pm':
6 = '12pm'
);
你能告訴我們HTML部分 –
@Light更新:)感謝 – user3453264
你'如果別人( 0 =「我們是從週一至週一至週一至週六開放」: 1 =「18:00」: 2 =' 6pm': 3 ='6pm': 4 ='12pm': 5 ='12pm': 6 ='12pm' );''錯誤事件'$(「#open_close」)。html(.. '不正確 – Satpal