最新赞助活动温馨提示:自愿赞助服务器费用,学生和没有工作的整站资源免费下载!
头像

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

来源:http://erdangjiade.com/topic/132921.html H5程序员 2017-10-29 20:28浏览(105)

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('memo')">
    <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('msg');
}function loadStorage(id){
    var result = "<table border = '1'>";    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('msg');
}

!!!!效果图

这里写图片描述

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('memo')">
    <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('msg');
}function loadStorage(id){
    var result = "<table border = '1'>";    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('msg');
}

!!!!效果图

这里写图片描述

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

评论0
头像

友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群

1 2