【1】先下载jQuery.cookie插件:使用帮助请参考链接(https://github.com/carhartl/jquery-cookie)。
【2】安装插件:
[html] view plain copy
- <script type="text/javascript" src="<%=basePath%>ie6/crm2/js/lib/cookies/jquery.cookie.js"></script>
【3】功能逻辑:
[javascript] view plain copy
- //判断之前是否有设置cookie,如果有,则设置【记住我】选择框
- if($.cookie(‘absms_crm2_userName‘)!=undefined){
- $("#rememberMe").attr("checked", true);
- }else{
- $("#rememberMe").attr("checked", false);
- }
- //读取cookie
- if($(‘#rememberMe:checked‘).length>0){
- $(‘#userName‘).val($.cookie(‘absms_crm2_userName‘));
- $(‘#password‘).val($.cookie(‘absms_crm2_password‘));
- }
- //监听【记住我】事件
- $("#rememberMe").click(function(){
- if($(‘#rememberMe:checked‘).length>0){//设置cookie
- $.cookie(‘absms_crm2_userName‘, $(‘#userName‘).val());
- $.cookie(‘absms_crm2_password‘, $(‘#password‘).val());
- }else{//清除cookie
- $.removeCookie(‘absms_crm2_userName‘);
- $.removeCookie(‘absms_crm2_password‘);
- }
- });
【4】使用
[html] view plain copy
- <tr>
- <td width="60">账 号:</td>
- <td width="244"><input id="userName" name="userName" type="text" class="inp_01" /></td>
- </tr>
- <tr>
- <td>密 码:</td>
- <td><input id="password" name="password" type="password" class="inp_01" /></td>
- </tr>
- <tr>
- <td> </td>
- <td><input id="rememberMe" type="checkbox"/> 记住我</td>
- </tr>
时间: 2024-10-24 23:06:08