h5 localStorage本地存儲


用戶名:<input type="text" id="txtname"/>
密碼:<input type="text" id="txtpwd1"/>
重復密碼:<input type="text" id="txtpwd2"/>
<button onclick="register()">注冊</button>
<button onclick="show()">顯示</button>
function register(){
   // console.log("ok");
    var use={};
    use.name=document.getElementById("txtname").value;
    use.pwd=document.getElementById("txtpwd1").value;
//文本框驗證(此處省略)
    localStorage.setItem("useinfo",JSON.stringify(use));  //JSON.stringify  用於從一個對象解析出字符串
  //"name":"11","pwd":"12345678"}
}

//
function show(){

  var data=JSON.parse(localStorage.geteItem("useinfo"));  //date為json數據,JSON.parse() 用於從一個字符串中解析出json對象
//Object {name: "11", pwd: "12345678"}
  console.log(data.name+"\n"+data.pwd);
}
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM