2
使用下面的代码示例,我如何利用jquery cookie插件,以便每个div元素的切换状态在浏览器会话之外保持不变。坚持使用Cookie切换状态
谢谢。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
};
$(document).ready(function(){
$('.toggle').show();
$('.hide').click(function(){
var t = $(this);
// toggle hidden div
t.parent().find('.toggle').slideFadeToggle(400, function(){
// determine which image to use if hidden div is hidden after the toggling is done
var imgsrc = ($(this).is(':hidden')) ? 'http://i47.tinypic.com/vg0hu0.gif' : 'http://i45.tinypic.com/281tsle.gif';
// update image src
t.attr('src', imgsrc);
});
})
})
</script>
</head>
<body>
<div class="wrapper">
<img class="hide" src="http://i45.tinypic.com/281tsle.gif" /> Header Text 1
<div class="toggle">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
</div>
<p>
<div class="wrapper">
<img class="hide" src="http://i45.tinypic.com/281tsle.gif" /> Header Text 2
<div class="toggle">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
</div>
</p>
</body>
</html>
谢谢你的回复,我几乎知道这个过程的“流程”,我缺乏的是一个代码示例,告诉我它是如何完成的。 – Sandra 2010-06-28 23:44:21
@Sandra:我正在研究一个我已经添加到我的答案中的例子。它展示了基本的想法。 – 2010-06-28 23:49:09
对不起,我只是最后一个问题,如果我可以。如果一个div被设置为折叠状态,然后刷新页面,则切换动画会被踢出,这将显示div从展开到折叠状态。声明我做错了什么或者是否按设计设计? – Sandra 2010-06-29 00:20:11