首页 >web前端 >H5教程 >Html5学习之旅-html5的留言记事本开发(17)

Html5学习之旅-html5的留言记事本开发(17)

黄舟
黄舟原创
2017-02-17 14:54:162140浏览

web留言记事本的开发

!!!!!代码如下

index.html的代码

<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>H5表格提交</title>
    <script src="appWeb.js"></script></head><body>
    <p id="msg"></p>
    <textarea id="memo" cols="60" rows="10"></textarea><br/>
    <input type="button" value="追加数据" onclick="saveStorage(&#39;memo&#39;)">
    <input type="button" value="删除数据" onclick="clearStorage()"></body></html>

js的代码

function saveStorage(id){
    var data = document.getElementById(id).value;    var time = new Date().getTime();
    localStorage.setItem(time,data);
    loadStorage(&#39;msg&#39;);
}function loadStorage(id){
    var result = "<table border = &#39;1&#39;>";    for(var i = 0;i < loadStorage.length;i++){        var key = localStorage.key(i);        var value = localStorage.getItem(key);        var date = new Date();
        date.setTime(key);
        result += "<tr><td>"+value+"</td><td>"+date+"</td></tr>";
    }
    result += "</table>";    var target = document.getElementById(id);
    target.innerHTML = result;
}function clearStorage(){
    localStorage.clear();
    loadStorage(&#39;msg&#39;);
}

!!!!效果图

这里写图片描述

web留言记事本的开发

!!!!!代码如下

index.html的代码

<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>H5表格提交</title>
    <script src="appWeb.js"></script></head><body>
    <p id="msg"></p>
    <textarea id="memo" cols="60" rows="10"></textarea><br/>
    <input type="button" value="追加数据" onclick="saveStorage(&#39;memo&#39;)">
    <input type="button" value="删除数据" onclick="clearStorage()"></body></html>

js的代码

function saveStorage(id){
    var data = document.getElementById(id).value;    var time = new Date().getTime();
    localStorage.setItem(time,data);
    loadStorage(&#39;msg&#39;);
}function loadStorage(id){
    var result = "<table border = &#39;1&#39;>";    for(var i = 0;i < loadStorage.length;i++){        var key = localStorage.key(i);        var value = localStorage.getItem(key);        var date = new Date();
        date.setTime(key);
        result += "<tr><td>"+value+"</td><td>"+date+"</td></tr>";
    }
    result += "</table>";    var target = document.getElementById(id);
    target.innerHTML = result;
}function clearStorage(){
    localStorage.clear();
    loadStorage(&#39;msg&#39;);
}

!!!!效果图

这里写图片描述

 以上就是Html5学习之旅-html5的留言记事本开发(17)的内容,更多相关内容请关注PHP中文网(www.php.cn)!


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn