【问题标题】:How do I get the output to display inside the div after the user fills in the prompts? [closed]用户填写提示后,如何让输出显示在 div 内? [关闭]
【发布时间】:2021-10-17 13:17:14
【问题描述】:

当我在浏览器中测试此代码时,提示弹出得很好,但在全部填写后屏幕上什么也没有。有什么我想念的吗...?

<!DOCTYPE html>
<html>
    <head>
        <title>Mad Libs</title>
    </head>
    <body>
    <div id="out"></div>
        <script>
        var properName = prompt("Enter a proper name");
        var verb = prompt("Enter a verb (past tense)");
        var verb2 = prompt("Enter a second verb (past tense)");
        var adj = prompt("Enter an adjective");
        var adj2 = prompt("Enter another adjective");

        var out = "Roses are red. Violets are blue. <br/>";
        out += properName + "left town without wearing a shoe. <br/>";
        out += properName + " " + verb + "<br/>";
        out += "And " + properName + " " + verb2 + "<br/>";
        out += "But I am " + adj + " " + properName + "thought. <br/>";
        out += "And kind of " + adj2 + " too!";
            
        document.getElementByID('out').innerHTML = out;
        </script>
    </body>
</html>

【问题讨论】:

    标签: javascript html variables output


    【解决方案1】:

    document.getElementByID 应该是document.getElementById:

    <!DOCTYPE html>
    <html>
        <head>
            <title>Mad Libs</title>
        </head>
        <body>
        <div id="out"></div>
            <script>
            var properName = prompt("Enter a proper name");
            var verb = prompt("Enter a verb (past tense)");
            var verb2 = prompt("Enter a second verb (past tense)");
            var adj = prompt("Enter an adjective");
            var adj2 = prompt("Enter another adjective");
    
            var out = "Roses are red. Violets are blue. <br/>";
            out += properName + "left town without wearing a shoe. <br/>";
            out += properName + " " + verb + "<br/>";
            out += "And " + properName + " " + verb2 + "<br/>";
            out += "But I am " + adj + " " + properName + "thought. <br/>";
            out += "And kind of " + adj2 + " too!";
                
            document.getElementById('out').innerHTML = out;
            </script>
        </body>
    </html>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 2013-08-03
      • 1970-01-01
      • 2023-01-07
      • 2019-01-01
      • 2013-08-14
      相关资源
      最近更新 更多