简体   繁体   English

我找不到我的代码有什么问题

[英]I cannot find what is wrong with my code

I cannot find out why the first button in the div on this code does not work on HTML files.我不知道为什么此代码的 div 中的第一个按钮对 HTML 文件不起作用。 I have checked many javaScript and HTML validators but none of them work.我检查了许多 javaScript 和 HTML 验证器,但它们都不起作用。 on codecademy.com and w3schools.com it works but not on HTML files.在 codecademy.com 和 w3schools.com 上它有效,但不适用于 HTML 文件。

<!DOCTYPE html>
<html>
 <head>
  <style>
   #b1 {
        background-image: url('http://images2.fanpop.com/image/photos/14600000/egypt-egyptian-history-14635051-430-287.jpg');
        background-repeat: no-repeat;
        background-size: cover;
    }

    div {
        width: 990px;
        padding: 25px;
        border: 2px solid navy;
        margin: 25px;
    }
</style>
</head>
<body id="b1">
 <script>
    var b = 0;
    var a = function () {
        var q = "blah"
        document.getElementById('r').innerHTML = q;
    };

    var g = function () {
        location.reload();
    };
    var ab = function () {
        var p = "blah";
        document.getElementById('r').innerHTML = p;
    };
    var aq = function () {
        var an = "blah";
        document.getElementById('r').innerHTML = t;
    };
    var di = function () {
        var pe = "blah";
        document.getElementById('r').innerHTML = pe;
    };
    var e = true;
    var a = function () {
        if (e === true) {
            e = false;
            document.getElementById('a').innerHTML = "Ancient Egypt";
        }
        else {
            e = true;
            document.getElementById('a').innerHTML = "Erik Low\'s";
        }

    }
    setInterval(function () { a(); }, 4000);
</script><center>
    <div style="background:white" id="r">

        <h1>Ancient Egypt</h1>
        <h2>Achievements</h2>
        <hr />
        <button onclick="a();">Pyramids</button><br /><br />
        <button onclick="ab();">The Sphinx</button><br /><br />
        <button onclick="aq();">Writing</button><br /><br />
        <button onclick="v();">Mummification</button><br /><br />
        <button onclick="di();">Valley Of The Kings</button><br /><br />
    </div>
</center>

You are missing a ;你缺少一个 ;

var q= "blah";

Also

document.getElementById('a')

This is null so there is no innerHTML of null.这是空值,因此没有空值的innerHTML。 You have no html tag with id = 'a'您没有 id = 'a' 的 html 标签

t variable, v function , semicolon missing in your JS code.您的 JS 代码中缺少 t 变量、v 函数、分号。

 <!DOCTYPE html>
    <html>
    <head>
    <style> #b1{
    background-image: url('http://images2.fanpop.com/image/photos/14600000/egypt-egyptian-history-14635051-430-287.jpg');
    background-repeat:no-repeat;

    background-size:cover;
    }
    div {
    width: 990px;
    padding: 25px;
    border: 2px solid navy;
    margin: 25px;
    }




    </style>
    </head>
    <body id="b1">
    <script>
    var b = 0;
    var a = function() {
    var q= "blah";
    document.getElementById('r').innerHTML = q; 
    };

    var g = function(){
    location.reload();
    };

    var v=function(){
        alert("function v calling");
    }
    var ab=function(){
        var p = "blah";
        document.getElementById('r').innerHTML = p;
         };
         var aq = function(){
        var an = "blah";  
        var t="writing";
     document.getElementById('r').innerHTML = t;
             };
             var di = function(){
                 var pe = "<h1>Valley Of The Kings</h1><hr/><br/><img src=\"http://3.bp.blogspot.com/-YUOUb6HSFcg/UbjX528O3zI/AAAAAAAAFw4/BXgpfsGvHgw/s1600/t1.jpg\" width=\"700\"><br/><h2>What Is The Valley Of The Kings</h2><p>The Valley Of The Kings is a valley in which many pharaohs were burried.</p><br/><h2>Who Was Burried There</h2><br/><p>In the East Valley Of The Kings Ramesses VII,<br/> Ramesses IV, Ramesses XI, Ramesses IX, Ramesses II,<br/> Merenptah, Ramesses V, Ramesses VI, Amenmesse,<br/> Ramesses III, Ramesse Khamenteru, Amenherkhepshef,<br/> Mentuherkhepshef, Twosret, Setnakhte, Seti II, Ramesses I, Seti I, Ramesses X, Mentuherkhepshef,<br/> Thutmose I, Hatshepsut, Tia\'a, Thutmose III, Amenhotep II, Maiherpri,<br/> Amenhotep I, Hatshepsut-Meryetre, Thutmose IV, Userhet, Yuya,<br/> Tjuyu, Siptah, Amenemopet called Pairy, Akhenaten, Horemheb,<br/> Sitre In, and Tutankhamen were burried.<br/> In the West valley Ay, Akhenaten, and Amenhotep III were burried.</p><br/><br/><p>Sources</p>";
                 document.getElementById('r').innerHTML = pe;
                 };
                 var e=true;
    var a = function() {
    if (e===true){
    e=false;
    document.getElementById('r').innerHTML = "Ancient Egypt";
    }
    else{
    e=true;
    document.getElementById('r').innerHTML = "Erik Low\'s";
    }

    }
    setInterval(function(){ a(); }, 4000);
    </script><center>
    <div style="background:white" id="r">

    <h1>Ancient Egypt</h1>
    <h2>Achievements</h2>
    <hr/>
    <button onclick="a();">Pyramids</button><br/><br/>
    <button onclick="ab();">The Sphinx</button><br/><br/>
    <button onclick="aq();">Writing</button><br/><br/>
    <button onclick="v();">Mummification</button><br/><br/>
    <button onclick="di();">Valley Of The Kings</button><br/><br/>
    </div>
    </center>

    </body>
    </html>

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

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