【jQuery】利用jQuery實現“記住我”的功能

來源:互聯網
上載者:User

標籤:log   ace   fine   move   false   ring   alt   實現   com   

【1】先下載jQuery.cookie外掛程式:使用協助請參考連結(https://github.com/carhartl/jquery-cookie)。

【2】安裝外掛程式:

 

[html] view plain copy
  1. <script type="text/javascript" src="<%=basePath%>ie6/crm2/js/lib/cookies/jquery.cookie.js"></script>  


【3】功能邏輯:


 

[javascript] view plain copy
  1. //判斷之前是否有設定cookie,如果有,則設定【記住我】選擇框  
  2.     if($.cookie(‘absms_crm2_userName‘)!=undefined){  
  3.         $("#rememberMe").attr("checked", true);  
  4.     }else{  
  5.         $("#rememberMe").attr("checked", false);  
  6.     }  
  7.       
  8.     //讀取cookie  
  9.     if($(‘#rememberMe:checked‘).length>0){  
  10.         $(‘#userName‘).val($.cookie(‘absms_crm2_userName‘));  
  11.         $(‘#password‘).val($.cookie(‘absms_crm2_password‘));  
  12.     }  
  13.       
  14.     //監聽【記住我】事件  
  15.     $("#rememberMe").click(function(){  
  16.         if($(‘#rememberMe:checked‘).length>0){//設定cookie  
  17.             $.cookie(‘absms_crm2_userName‘, $(‘#userName‘).val());  
  18.             $.cookie(‘absms_crm2_password‘, $(‘#password‘).val());  
  19.         }else{//清除cookie  
  20.             $.removeCookie(‘absms_crm2_userName‘);  
  21.             $.removeCookie(‘absms_crm2_password‘);  
  22.         }  
  23.     });  


【4】使用

[html] view plain copy
    1. <tr>  
    2.     <td width="60">賬  號:</td>  
    3.     <td width="244"><input id="userName" name="userName" type="text" class="inp_01" /></td>  
    4.   </tr>  
    5.   <tr>  
    6.     <td>密  碼:</td>  
    7.     <td><input id="password" name="password" type="password" class="inp_01" /></td>  
    8.   </tr>  
    9.   <tr>  
    10.     <td> </td>  
    11.     <td><input id="rememberMe" type="checkbox"/> 記住我</td>  
    12.   </tr> 

【jQuery】利用jQuery實現“記住我”的功能

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.