Cookie localStorage front-end and a combination of transmission parameters across the page

A page
html code:
 姓名:<input type="text" id="name1">
 年龄:<input type="text" id="age1">
<button id="click_btn">点击</button>
View Code
js code:
 // localStorage.name = "John Doe"; 
        // localStorage.age = 18 is; // can store multiple sets of data 


        var BTN = document.getElementById ( "click_btn" ); 
        btn.onclick = function () {
             // var username = 'zhangsan' 
            var username = document.getElementById ( "NAME1" ) .Value;
             // var userAge = '13 is'; 
            var userAge = document.getElementById ( "AGE1" ) .Value;
             // store all values to the array 
            var = arrLocalStorage [username, userAge]; 

            // store, IE6 ~ 7 cookie other browsers HTML5 local storage 
            IF (window.localStorage) { 
                localStorage.setItem ("localName", arrLocalStorage);
            } else {
                Cookie.write("localName", arrLocalStorage);
            }

        }

        //参考了 https://blog.csdn.net/ZhushiKezhang/article/details/80360998
View Code
B page
js code:
 // var myname = localStorage [ "name"]; // myname is Zhang 
    // the console.log (myname) 

    // use localStorage Cookie and combined transmission parameters 
    
    // condition determination takes localStorage stored value or a stored cookie value 
    var StoreDate = window.localStorage localStorage.getItem ( "the localName"): Cookie.read ( "the localName"? );
     var arrStoreDate = StoreDate.split ( "," ); 

    the console.log (arrStoreDate); // remove any memory the value of 

    the console.log (arrStoreDate [ 0]); // retrieves the first name value 
    the console.log (arrStoreDate [. 1]); // remove the second value Age 


    // for (var I = 0; I <arrStoreDate .length; I ++) { 
    //     var liHtml = "<li>" + arrStoreDate[i] + "</li>";
    //     $('.list').append(liHtml);
    // }
View Code

Guess you like

Origin www.cnblogs.com/heyiming/p/11344219.html
Recommended