亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用input()輸入后如何長久的保存在程序中,下次再運行代碼也不用輸入?

用input()輸入后如何長久的保存在程序中,下次再運行代碼也不用輸入?

椰蓉罐頭 2016-10-08 20:38:10
可以這樣嗎?
查看完整描述

1 回答

已采納
?
木子_123

TA貢獻10條經驗 獲得超5個贊

如果不用加密的話,用js就可以,其實就是一個記住用戶名密碼的功能

<body>

?賬號:<input>

? ? 密碼:<input>

? ? 記住密碼:<input type="checkbox">

? ? <button onclick="fn()">登錄</button>

<script>

? ? var user = document.getElementsByTagName("input")[0],

? ? ? ? pass = document.getElementsByTagName("input")[1],

? ? ? ? check = document.getElementsByTagName("input")[2],

? ? ? ? loUser = localStorage.getItem("user") || "";

? ? ? ? loPass = localStorage.getItem("pass") || "";

? ? ? ? user.value = loUser;

? ? ? ? pass.value = loPass;

? ? ? ? if(loUser !== "" && loPass !== ""){

? ? ? ? ? ? check.setAttribute("checked","");

? ? ? ? }

? ? function fn(){

? ? ? ? if(check.checked){

? ? ? ? ? ? localStorage.setItem("user",user.value);

? ? ? ? ? ? localStorage.setItem("pass",pass.value);

? ? ? ? }else{

? ? ? ? ? ? localStorage.setItem("user","");

? ? ? ? ? ? localStorage.setItem("pass","");

? ? ? ? }

? ? }

</script>

</body>


查看完整回答
反對 回復 2016-10-09
  • 1 回答
  • 0 關注
  • 1791 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號