您现在的位置:首页 >> JS&Jq >> 内容

jQuery的cookie插件实现保存用户的数据

时间:2014-4-15 15:09:40 点击:

  核心提示:1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
html>
 
   
    <title>cookies.html</title>
     
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
     
   <style type="text/css">
    .txt{
        width: 150px;
        height:20px;
        border: 1px blue solid;
        border-radius:0.5em;
        margin-bottom: 5px;
        padding-left: 5px;
    }
 
</style>
<script type="text/javascript" src="../js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="../js/jquery.cookie.js"></script>
<script type="text/javascript">
    $(function(){
     
     
        if($.cookie("name")){
        //取值如果存在则赋值
        $("#username").val($.cookie("name"));
         
        }
         
         
        $("#mycookie").submit(function(){
 
          //如果选中了保存用户名选项
            if($("#chkSave").is(":checked")){
             
                //设置Cookie值
                $.cookie("name",$("#username").val(),{
                    expires:7,//设置保存期限
                    path:"/"//设置保存的路径
                 
                });
                 
            }else{
             
            //销毁对象
            $.cookie("name",null,{
                path:"/"
             
               });
            }
             
    return false;
        });
     
    });
 
 
</script>
   
    
    <form action="#" method="get" id="mycookie">
     
        <div>
            用户名:<br>
            <input id="username" name="username" type="text" class="txt">
        </div>
        <div>
            密码:<br>
            <input id="password" name="password" type="password" class="txt">
        </div>
        <div>
            <input id="chkSave" type="checkbox">是否保存用户名
        </div>
        <div>
            <input id="cookBtn" class="btn" type="submit" value="提交">
        </div>
     
     </form>
  
   
  

作者:不详 来源:网络
共有评论 1相关评论
发表我的评论
  • 大名:
  • 内容:
  • 青春网络编程技术(www.qcfupo.com) © 2020 版权所有 All Rights Reserved.
  • Powered by qcfupo! V3.0sp1
  • 百度友情链接: 百家乐[www.chinawestnews.net/aomenbaijiale/] 赌博网[www.chinawestnews.net/amdbwz/] 海立方[www.bjl.gov.cn/bjgylc/] 娱乐城[www.gtxrmzf.gov.cn/mapai/] 娱乐城[www.hfsf.gov.cn/yfgj/] 威尼斯人[www.hllinkou.gov.cn/baijile/] 澳门威尼斯[www.jjwgj.gov.cn/wnsr/] 888真人[www.lagm.gov.cn/888zhenren/] 百乐坊[www.laoling.gov.cn/blfylc/] 现金网[www.longyu.gov.cn/xjw/] 百家乐[www.chinawestnews.net/ambjl/] 新葡京娱乐场[www.sjzedu.gov.cn/jsylc/] 时时彩[www.snjw.gov.cn/ssc/] 赌博[www.chinawestnews.net/aomendubo/]