【问题标题】:how to set the hidden and shown column after refreshing the page刷新页面后如何设置隐藏列和显示列
【发布时间】:2017-04-18 16:02:59
【问题描述】:

你好,我需要帮助在 javascript 中设置 cookie,因为这是我第一次制作 cookie,我无法在浏览器中加载 cookie。这是我的 html 和 jquery 代码

<html>
<head>
</head>
<body>
<table>
    <tr>
    <th><b class='show' style='cursor:pointer;font-weight: unset;'>Datum</b><b class='hide' style='display:none;cursor:pointer;font-weight: unset;'>Datum</b></th>
    <th><b class='show1' style='cursor:pointer;font-weight: unset;'>Zeitfenster</b><b class='hide1' style='display:none;cursor:pointer;font-weight: unset;'>Zeitfenster</b></th>
    <th class='orgaunit' style='display:none;'>Betriebstelle</th>
    <th class='orgaitem' style='display:none;'>Betriebselemente</th>
    <th>Zeit (von - bis)</th>
    <th>Pause (von - bis)</th>
    <th>Stunden</th>
    <th>Details</th>
    <th>Bemerkung</th>
    </tr>
    <tr>
   <td> hello</td> 
    <td style='text-align:left;padding-left:4%;' >hello2</td>
    <td class='orgaunit' style= 'display:none;'>hello3 </td>
    <td class='orgaitem' style= 'display:none;'>hello4 </td>
    <td> hello 5</td>
    <td>"hello 6</td>
    <td  style="padding-right:15px;" >hello 7</td>
    <td>hello 8</td>
    <td>hello 9</td>
    </tr></table>
<script src="2.1.1.js"></script>
<script>
function setCookie(c_name, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" +     exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
 }

function getCookie(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
    x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
    y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
    x = x.replace(/^\s+|\s+$/g, "");
    if (x == c_name) {
        return unescape(y);
    }
  }
 }
 $(document).ready(function(){
 var theColumn = $(".show").click(function(){
 $(".hide").css({display:"inline-block"});
 $(".show").css({display:"none"});
 $(".orgaunit").css({display:"table-cell"});
 setCookie("selectedColumn", theColumn, 1);

  });
  //setCookie("selectedColumn", theColumn, 3);
 });

 $(document).ready(function() {
 $(".show").click(function(){
     getCookie("selectedColumn");
   });
 });

 $(document).ready(function(){
 var theColumn2 =  $(".hide").click(function(){
 $(".show").css({display:"inline-block"});
 $(".hide").css({display:"none"});
 $(".orgaunit").css({display:"none"});
 });
  setCookie("selectedColumn2", theColumn2, 3);
});
$(document).ready(function(){
  var theColumn3 =  $(".MainContent").ready(function(){
  $(".show").css({display:"inline-block"});
  $(".hide").css({display:"none"});
  $(".orgaunit").css({display:"none"});
  });
  setCookie("selectedColumn3", theColumn3, 3);
});
$(document).ready(function() {
   $(".hide").value = getCookie("selectedColumn");
});

$(".show1").click(function(){
   $(".hide1").css({display:"inline-block"});
   $(".show1").css({display:"none"});
   $(".orgaitem").css({display:"table-cell"});
});

$(".hide1").click(function(){
   $(".show1").css({display:"inline-block"});
   $(".hide1").css({display:"none"});
   $(".orgaitem").css({display:"none"});
});
</script>
</body>
</html>

我已经制作了一个显示的列并再次隐藏它是列Betriebstelle和列Betriebellement,在我刷新页面后它再次被隐藏我需要保存保存这些列的条件如果它显示或隐藏刷新页面后与我选择的相同

我所做的 cookie 是在浏览器中设置的,但我无法再次将其取回 请帮帮我

【问题讨论】:

  • 这里没有php代码
  • 我拿走了 php 代码,因为我不需要它,它只关心 javascript cookie 并使浏览器记住隐藏或显示列的情况
  • 然后从问题中删除 php 标签。它会误导其他专业人士
  • 好吧我很抱歉:(
  • 谁能帮帮我

标签: javascript jquery html cookies


【解决方案1】:

为什么要使用 cookie?如果您不需要服务器端的 cookie,我会使用 localStorage

【讨论】:

  • 我很好地设置了 localStorage 和 cookie,但是当我刷新浏览器时完全忘记它们
  • 如果您不介意,请您帮帮我,并在此代码中制作它
  • 你能帮我吗@Brissy
猜你喜欢
  • 2014-11-30
  • 1970-01-01
  • 2019-03-25
  • 1970-01-01
  • 2012-11-05
  • 2020-09-24
  • 1970-01-01
  • 1970-01-01
  • 2013-03-01
相关资源
最近更新 更多