简体   繁体   English

无法弄清楚为什么我的标题的其余部分不会显示

[英]Can't figure out why the rest of my header will not show

    <head>

function that is called when the page loads 页面加载时调用的函数

    <body onload="myOnload()">

header div with custom graphic 具有自定义图形的标题div

    <div id="header">
    <img src="resumeheader.png" alt="Header" style="width:750px;height:100px;">
    <h2>Pay Calculator</h2>
    <h3></h3>

    <script>

this function shows the hour 此功能显示小时

    function myOnload(){
        var d = new Date();
        var n = d.getHours();
        document.getElementById("header").innerHTML = n;

if...else if... else statement for time for greeting 如果...否则,如果...否则声明要问候的时间

    if (new Date().getHours() < 12) {
    document.getElementById("header").innerHTML = "Enjoy the rest of your morning!";
    } else if (new Date().getHours() < 17) {
    document.getElementById("header").innerHTML = "Enjoy the afternoon!";
    } else  (new Date().getHours() > 17) 
    document.getElementById("header").innerHTML = "Have a good evening!";

these variables should make it possible for the code to show in my header 这些变量应该使代码可以显示在我的标题中

    var firstVariable = document.createElement("H3"); 
    var secondVariable = document.createTextNode(n);
    firstVariable.appendChild(secondVariable);
    document.body.appendChild(firstVariable); 
    }


    </script>

end javascript 结束javascript

    </div>
    </body>
    </head>

you need to take care of your code like this line } else (new Date().getHours() > 17) 您需要像下面这样处理代码: } else (new Date().getHours() > 17)

try the following code: 试试下面的代码:

 <html> <head> </head> <body onload="myOnload()"> <div id="header"></div> <div id=img><img src="resumeheader.png" alt="Header" style="width:750px;height:100px;"></div><div id=h2> <h2>Pay Calculator</h2> <h3></h3></div> <script> function myOnload(){ var d = new Date(); var n = d.getHours(); document.getElementById("header").innerHTML = n; if (n < 12) { document.getElementById("header").innerHTML = "Enjoy the rest of your morning!"; } else if (n < 17 && n > 12) { document.getElementById("header").innerHTML = "Enjoy the afternoon!"; } else { document.getElementById("header").innerHTML = "Have a good evening!"; } var firstVariable = document.createElement("H3"); var secondVariable = document.createTextNode(n); firstVariable.appendChild(secondVariable); document.body.appendChild(firstVariable); } </script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM