首页 > 程序开发 > web前端 > JavaScript >

jQuery操作cookie

2012-04-06

<html><head> <title>Cookie测试</title> <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script src="Scripts/jquery.cookie.js" type="text/javascript"></script> <scrip...

<html>
<head>
<title>Cookie测试</title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery.cookie.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
if ($.cookie("content")) {
$("#txtInput").val($.cookie("content"));
}

// 保存1天。若不加expires这个属性,那么浏览器关闭后该cookie就会被清除
$(&#39;#btn&#39;).click(function () {
var txt = $("#txtInput").val();
$.cookie("content", txt, {expires:1});
});
});
</script>
</head>
<body>
<input id="txtInput" type="text" />
<input id="btn" type="button" value="查询" />
</body>
</html>

摘自 IT胖子的专栏
相关文章
最新文章
热点推荐