0

I have a page with list items (links) that I need to be able to hide/show from my admin page.

How do I get it to work that if i press a button in my admin page, it hides list items that are on a different page?

<script type="text/javascript">
$(document).ready(function(){
    $("button").click(function(){
       $("a").css("display","none");
    });
});
</script>

The above code works to hide elements that are on the same page only.

4

1 回答 1

2

我能想到的最好的(仅使用客户端脚本)

是在第一页点击时创建一个cookie ,

在第二页中,当窗口在失去焦点后获得焦点时(意味着用户离开页面选项卡并返回到它),检查该 cookie ,如果已设置则隐藏。或者,如果您希望用户在进入时已经将其隐藏,则在窗口模糊时开始检查直到窗口聚焦。

您可以使用jquery cookie 插件(或常规 js)并执行以下操作:

$("button").click(function(){
     $.cookie('the_cookie', 'the_value', { expires: 1, path: '/' });
 });

在第 2 页:

$(window).focus(function(){
  if($.cookie('the_cookie') == "the_value"){
      $("a").hide();
      $.removeCookie('the_cookie'); // so i't won't happen again
  }
  else { //if it already was
      $("a").show();
  }
});
于 2013-07-03T14:14:35.803 回答