我需要帮助,我有一个脚本,保持由jquery cookie的更改,如果我重新加载它的工作页面,但如果刷新div不工作了。 我错在哪里?Jquery Cookie丢失在Div刷新
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="scripts/jquery.cookie.js"></script>
<style>
table {
border: 1px solid #999;
}
#refresh{
text-align:center;
}
#counter{
text-align:center;
}
</style>
</head>
<body>
<div id="counter">0
</div>
<div id="container">
<div id="refresh">
<table cellpadding="0" cellspacing="5" width="100%" height="60%">
<tr>
<td width="20%" height="20%"><input class="box" type="checkbox" name="1" /></td>
<td width="20%" height="20%"><input class="box" type="checkbox" name="2" /></td>
<td width="20%" height="20%"><input class="box" type="checkbox" name="3" /></td>
</tr>
<tr>
<td width="20%" height="20%"><input class="box" type="checkbox" name="4" /></td>
<td width="20%" height="20%"><input class="box" type="checkbox" name="5" /></td>
<td width="20%" height="20%"><input class="box" type="checkbox" name="6" /></td>
</tr>
</table>
</div>
</div>
<script>
var isScrolling = false;
var lastScrollPos = 0;
var counter = 1;
$(function() {
$('#refresh').on('scroll', function() {
isScrolling = true;
lastScrollPos = this.scrollTop;
});
refreshTimer = setInterval(agg_menu, 10000);
var updateTotal = function(){
$("input.box").each(function() {
var mycookie = $.cookie($(this).attr('name'));
if (mycookie && mycookie == "true") {
$(this).prop('checked', mycookie);
}
});
$("input.box").change(function() {
$.cookie($(this).attr("name"), $(this).prop('checked'), {
expires: 365
});
});
}
updateTotal();
function agg_menu(){
if (!isScrolling) {
var referer = 'pppp.php #refresh';
$("#container").load(referer);
$("#counter").text(counter++);
updateTotal();
}
isScrolling = false;
}
});
</script>
我不知道这是一个jQuery Cookie或函数each()的问题。
您正在将cookie中的布尔值“true”存储在cookie中,但是当您读取cookie时,您将它与字符串“true”进行比较。 – Barmar 2014-08-29 11:06:14