cookie的用法

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 

  <title>jQuery学习2</title> 

//用到的两个jQuery的js

  <script type="text/javascript" src="resource/jquery-easyui-1.3.2/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="resource/jquery-easyui-1.3.2/jquery.cookie.js"></script>
  <script type="text/javascript"> 

//自动加载的是将cookie中存的值取出来,显示在相应的文本框中。    

$(function () { 

      alert("ccccccccc");
      $("#username").val($.cookie("username")); 
      if ($.cookie("like") == "刘德华") { 
        $(":radio[value='刘德华']").attr("checked", 'checked') ;
      } 
      else { 
        $(":radio[value='张学友']").attr("checked", 'checked') ;

      } 



      $(":button").click(function () { 

//将文本框username的值存入cookie中,取名为username

        $.cookie("username", $("#username").val(), { 
          path: "/", expires: 7 

        }) 

       //将单选框理科的值存入cookie中,取名为like

        $.cookie("like", $(":radio[checked]").val(), { 
          path: "/", expiress: 7 
        }) 
      }) 
    }) 
  </script> 
</head> 
<body> 
  <p><input type="text" id="username" value="" /></p> 
  <p> 
    <input type="radio" name="like" value="刘德华" />刘德华 
    <input type="radio" name="like" value="张学友" />张学友 
  </p> 
  <p><input type="button" value="保存" /></p> 
</body> 
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值