利用cookie和jquery簡單實現登陸中的「記住我」功能

1、js如何判斷checkbox是否選中html

$("input[type='checkbox']").is(':checked')

2、簡單實現「記住我」jquery

一、htmlgit

    <div class="checkbox">
        <label>
          <input type="checkbox" value="記住我" id="remeber-me"  >記住我
        </label>
      </div>

二、本demo使用cookie來保存用戶名和密碼,其中cookie使用jquery-cookie.js插件,使用幫助請參考連接(https://github.com/carhartl/jquery-cookie)。github

三、js相關操做cookie

  var name=$(".loginName").val();
  var password=$(".loginpwd").val();
  if($("input[type='checkbox']").is(":checked")==true){
        //保存數據到cookie
        $.cookie('name', name);
        $.cookie('password', password);
    }else{
        $.removeCookie('name');
        $.removeCookie('password');
    }
相關文章
相關標籤/搜索