簡體   English   中英

HTML5本地存儲輸入不顯示

[英]HTML5 Local Storage input not displaying

我正在努力查看我的代碼出了什么問題。 我已經編碼了一個本地存儲應用程序以顯示用戶輸入,但是正在輸入的內容並未顯示在屏幕上。

我將展示我的代碼,希望有人可以在某個地方看到錯誤,我認為它應該可以正常工作?

    <!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Premier League Site</title>
    <link rel="stylesheet" href="style.css"/>
    <script src="elliot.js"></script>
</head>
<body>
    <div id="wrapper">
    <header id="header">
    <h1>Premier League Site</h1>
    </header>

    <nav id ="Menu_Bar">
    <ul>
        <li>Home</li>
        <li>Teams</li>
        <li>Extras</li>
    </ul>

    </nav>

    <section id="sectionone">
        <form>
            <p>(key) One: <input type="text" id="one"></p>
            <p>(value) Two <textarea id="two"></textarea></p>
            <p><input type="button" id="button" value="Save"></p>
        </form>
    </section>
    <section id="sectiontwo">
        Stored Info should go here
    </section>  
    <footer id="footer">
        Elliot Harrison 2014
    </footer>
    </div>
</body>
</html>

那是我的HTML代碼,這是我的Javascript代碼。

    function doFirst(){
    var button = document.getElementbyId("button");
    button.addEventListener("click", saveStuff, false);
}

function saveStuff(){
    var one = document.getElementbyId("one").value;
    var two = document.getElementbyId("two").value;
    sessionStorage.setItem(one,two);

    display(one);
}

function display(one){
    var sectiontwo = document.getElementbyId("sectiontwo");
    var two = sessionStorage.getItem(one);
    sectiontwo.innerHTML = "Name of variable: "+one+"<br />Value: "+two;
}

window.addEventListener("load", doFirst, false);

誰能注意到任何錯誤?

謝謝!

編輯:注意到一個問題,我沒有“>”結尾

Javascript區分大小寫,您必須使用getElementById而不是getElementbyId

您的html中也存在另一個錯誤:

<p>(key) One: <input type="text" id="one" /></p>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM