尝试使用此脚本每天隐藏除下星期四以外的以下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;
};

10-08 16:16