• ws留言板


    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Web Storage之简易留言板</title>
    <style type="text/css">
    :root{
    margin: 5px;
    }
    textarea{
    100%;
    height:200px;
    }
    .liuyan-container{
    100%;
    }
    .well{
    position: fixed;
    top:20px;
    left:40%;
    }
    .fbsj{
    font-size:12px;
    }
    </style>
    </head>
    <script type="text/javascript" src="http://www.w3school.com.cn/jquery/jquery-1.11.1.min.js"></script>
    <link rel='stylesheet' href="http://apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.min.css">
    <script type="text/javascript">
    //var ws = sessionStorage;
    var ws = window.localStorage;
    var randomImg = "rar.png";
    function addInfo(){
    var liuyan = $("#liuyan");//为啥定义成全局变量为undefined?
    if(liuyan.val()==""){

    }
    var media = '<div class="media"><div class="media-left"><img src=images/"+randomImg+"></div><div class="media-body"></div></div>';
    var date = new Date();
    var text = '<div class="media"><div class="media-left"><img src="images/rar.png"></div>' +
    '<div class="media-body">'+liuyan.val()+"<br/> <span class='fbsj'>发表时间:"+date.toLocaleString()+'</span></div></div>'
    if(ws.MYBOARD){
    ws.MYBOARD += text;
    }else{
    ws.MYBOARD = text;
    }
    showInfo();
    }
    function showInfo(){
    var showliuyan = $("#showliuyan");
    showliuyan.html( ws.MYBOARD );
    }
    function clearInfo(){
    // ws.clear();
    ws.removeItem("MYBOARD");
    var showliuyan = $("#showliuyan");
    showliuyan.html("");
    $("#liuyan").val("");
    }
    window.onload = function(){
    showInfo();
    }
    </script>
    <body >
    <div class="well">Web Storage之简易留言板</div>
    <div class="row col-xs-6" id="showliuyan">
    </div>
    <hr>
    <textarea name="readTextArea" id="liuyan" placeholder="到此一游"></textarea>
    <div class="btn-group pull-right">
    <button id="addInfo" class="btn btn-success" onclick="addInfo()">留言</button>
    <button id="clearInfo" class="btn btn-primary" onclick="clearInfo()">清除</button>
    </div>
    </body>
    </html>

  • 相关阅读:
    jsonp跨域请求
    Vue-cli脚手架安装
    微信小程序获取用户信息“授权失败”场景的处理
    微信小程序
    获取url参数
    [git] github 使用简单记录
    [翻译]《高级英汉翻译理论与实践》摘录
    [Java] 模板引擎 Velocity 随笔
    [Java] 垃圾回收 ( Garbage Collection ) 的步骤演示
    [Java] 垃圾回收机制 ( Garbage Collection ) 简介
  • 原文地址:https://www.cnblogs.com/doublegi/p/5754085.html
Copyright © 2020-2023  润新知