js学习-简单的网页留言板

js学习-简单的网页留言板

知识点:
js学习-简单的网页留言板_第1张图片留言板.html


<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>网页留言板title>
    <script type="text/javascript" src="留言板.js">script>
head>
<body>
    <h1>简单的网页留言板h1>
    <textarea  id="dome" cols="60" rows="10">textarea>
    <br/>
    <input type="button" value="保存" onclick="saveStorage('dome');">
    <input type="button" value="清除" onclick="clearStorage('msg');">
    <input type="button" value="读取" onclick="loadStorage('msg');">
    <hr>
    <p id="msg">p>
body>
html>

留言板.js

function saveStorage(id) {
    var data = document.getElementById(id).value;
    var time = new Date().getTime();
    localStorage.setItem(time,data); //
    alert("数据已经被保存!"); //弹出对话框
    loadStorage('msg');
}
function loadStorage(id) {
    var reselt = '';//边框粗度for(var i =0; i < localStorage.length; i++){var key = localStorage.key(i);var value = localStorage.getItem(key);var data =newDate();
        data.setTime(key);var datestr = data.toUTCString();
        reselt +='';}
    reselt +='
'+'这是第'+ i +'条数据'+value+''+datestr+'
'
; var target = document.getElementById(id); target.innerHTML = reselt; } function clearStorage(id) { localStorage.clear(); alert("数据已经被成功删除!"); loadStorage('msg'); }

你可能感兴趣的:(js学习,javascript)