当用户单击链接时,寻找要设置的 cookie,它将打开 div,然后用户可以刷新页面并看到 div 仍然打开。
======HTML========
<a class="show-settings" href="#"></a>
=======jQuery=======
$(function () {
//Toggle Settings
var s = $("a.show-settings");
//On click to toggle settings
s.click(function () {
$("#s4-ribbonrow, #s4-titlerow").toggle();
});
//Add/Remove text
s.toggle(function () {
//$(this).text("Hide Settings");
}, function () {
//$(this).text("Show Settings");
});
我用过这个 jQuery 插件 https://github.com/carhartl/jquery-cookie之前非常可靠地达到了几乎完全相同的目的。它非常轻量级,并且它的文档非常容易理解。
所以你可以有这样的东西:
// This is assuming the two elements are hidden by default
if($.cookie('myCookie') === 'on')
$("#s4-ribbonrow, #s4-titlerow").show();
s.click(function () {
$("#s4-ribbonrow, #s4-titlerow").toggle();
// Toggle cookie value
if($.cookie('myCookie') === 'on')
$.cookie('myCookie', 'off');
else
$.cookie('myCookie', 'on');
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)