<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="resource/jquery-easyui-1.3.2/jquery.cookie.js"></script>
<script type="text/javascript">
$("#username").val($.cookie("username"));
if ($.cookie("like") == "刘德华") {
$(":radio[value='刘德华']").attr("checked", 'checked') ;
}
else {
$(":radio[value='张学友']").attr("checked", 'checked') ;
path: "/", expires: 7
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>
<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
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>