zoukankan      html  css  js  c++  java
  • JS web localStorage传值 coolie传值


    localStorage传值

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport"
    content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>localStorage传值页面</title>
    </head>
    <body>
    <input type="text" value="哥哥我爱你" class="inp1" id="bbb">
    <input type="button" value="添加" class="inp1 inp11" onclick="btn1()">
    </body>
    <script type="text/javascript">
    function btn1() {
    localStorage.setItem('biaoji', document.getElementsByClassName('inp1')[0].value);
    };
    </script>
    </html>


    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport"
    content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>获取数据页面</title>
    </head>
    <body>
    <div class="tianjia">
    获取值
    </div>
    <div class="clear">
    清除localStorage
    </div>
    <div class="zhi">

    </div>
    <script>
    document.getElementsByClassName('clear')[0].onclick = function () {
    localStorage.clear('biaoji');
    }

    document.getElementsByClassName('tianjia')[0].onclick = function () {
    document.getElementsByClassName('zhi')[0].innerHTML = localStorage.getItem('biaoji');
    }
    </script>
    </body>
    </html>

    cookie传值

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport"
    content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>1</title>
    <script src="../jquery/jquery.2.0.0.js"></script>
    <script src="./cookie.js"></script>
    </head>
    <body>
    <div>
    <span>姓名</span>
    <input type="text" value="gegegegegegege" class="name">
    </div>
    <div>
    <span>年龄</span>
    <input type="text" value="24" class="age">
    </div>
    <span onclick="cz()">传值</span>
    <script>
    function cz() {
    var data = {
    name: $('.name').val()
    , age: $('.age').val()
    };
    $.cookie('data', JSON.stringify(data));
    }
    </script>
    </body>
    </html>
    接受数据cookie

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport"
    content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>2</title>
    <script src="../jquery/jquery.2.0.0.js"></script>
    <script src="./cookie.js"></script>
    </head>
    <body>
    <script>
    $(function () {
    var jsdata = $.cookie('data');
    console.log(jsdata);
    });
    </script>
    </body>
    </html>
  • 相关阅读:
    OI 知识总览 算法篇 之 动态规划
    LeetCode 16.3Sum Closest
    LeetCode 1.Two sum
    leetCode 15. 3Sum
    leetCode 54. Spiral Matrix
    mybatis(视频)
    mybatis
    spring笔记
    Spring(一)
    Spring(二)
  • 原文地址:https://www.cnblogs.com/shenbo666/p/10266935.html
Copyright © 2011-2022 走看看