除星期四外每天隐藏 div
Hide a div everyday except Thursday
尝试使用此脚本每天隐藏以下 div,星期四除外。无法正常工作。 JS还是新手,我做错了什么?
<div class="row">
<script type="text/javascript">
onload=function(){
var rightNow = new Date();
var day = rightNow.getDay();
var hour = rightNow.getHours();
var newDisplay = 'none'; // unless we see otherwise
if(day==1 || day==2 || day==3 || day==5 || day==6 | day==7 ) { // days hidden
if((hour>= 1) && (hour<= 24)) {
newDisplay = 'block';
}
}
document.getElementById('thursday').style.display = newDisplay;
}
</script>
<div class="col-md-12" id="thursday">
<h3 style="font-family:Capture it;text-align:center">Warrior Pointe Radio - Live tonight on AllradioX - 1900 Pacific / 2200 Eastern</h3>
</div>
由于您最初将 display
设置为 none
,因此您只需检查是否是星期四即可将其设置为 block
。你也可以去掉 hour
的东西。这是最终代码:
onload = function(){
var day = (new Date()).getDay();
var newDisplay = 'none'; // unless it's Thursday
if(day == 4) newDisplay = 'block';
document.getElementById('thursday').style.display = newDisplay;
};
尝试使用此脚本每天隐藏以下 div,星期四除外。无法正常工作。 JS还是新手,我做错了什么?
<div class="row">
<script type="text/javascript">
onload=function(){
var rightNow = new Date();
var day = rightNow.getDay();
var hour = rightNow.getHours();
var newDisplay = 'none'; // unless we see otherwise
if(day==1 || day==2 || day==3 || day==5 || day==6 | day==7 ) { // days hidden
if((hour>= 1) && (hour<= 24)) {
newDisplay = 'block';
}
}
document.getElementById('thursday').style.display = newDisplay;
}
</script>
<div class="col-md-12" id="thursday">
<h3 style="font-family:Capture it;text-align:center">Warrior Pointe Radio - Live tonight on AllradioX - 1900 Pacific / 2200 Eastern</h3>
</div>
由于您最初将 display
设置为 none
,因此您只需检查是否是星期四即可将其设置为 block
。你也可以去掉 hour
的东西。这是最终代码:
onload = function(){
var day = (new Date()).getDay();
var newDisplay = 'none'; // unless it's Thursday
if(day == 4) newDisplay = 'block';
document.getElementById('thursday').style.display = newDisplay;
};