我想做以下事情:
如果时间在上午 7 点到下午 12 点(周一到周六)之间,则输出 html 代码,否则输出其他内容。
我目前已经尝试过:(忽略代码中的时间,这只是为了测试目的 - 我仍然希望它在早上 7 点到中午 12 点之间完成)
<script>
var today = new Date()
var curHr = today.getHours()
if (curHr < 12) {
phoneText .innerHTML="<div class='col-sm-6 col-md-3'><div class='support-box'><div class='icon green'><i class='fas fa-comments'></i></div><div class='details-holder'><div class='title'>Live Chat</div><a href='javascript:$zopim.livechat.window.show();' style='color:white;'>Start a live chat</a></div></div>";
} else if (curHr < 18) {
phoneText .innerHTML="<div class='col-sm-6 col-md-3'><div class='support-box'><div class='icon green'><i class='fas fa-comments'></i></div><div class='details-holder'><div class='title'>Live Chat</div><a href='javascript:$zopim.livechat.window.show();' style='color:white;'>Start a live chat</a></div></div>";
} else {
phoneText .innerHTML="<div class='col-sm-6 col-md-3'><div class='support-box'><div class='icon green'><i class='fas fa-comments'></i></div><div class='details-holder'><div class='title'>Live Chat</div><a href='javascript:$zopim.livechat.window.show();' style='color:white;'>Start a live chat</a></div></div>";
}</script>
然后我有 <div id="phone"></div>
相关分类