2017-04-18 62 views
0

您好,我需要在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和我刷新它被再次隐藏的页面后,我需要保存的条件保存这些列是否显示或隐藏的刷新页面后,这是相同的,因为我chosed

我没有在浏览器中设置好的饼干,但我不能拿回来aagin 请帮我

+0

这里没有php代码 – Akintunde007

+0

我拿走了php代码,因为我不需要它,它只关心javascript cookie,并让浏览器记住隐藏或显示列 – medo

+0

的情况,然后从问题中删除php标签。它会误导其他专业人士 – Akintunde007

回答

0

它你为什么要使用cookie?我会用localStorage这样做,如果你不需要服务器端的cookie。

+0

我设置了localStorage和cookie非常好,但是当我刷新浏览器时完全忘记了他们 – medo

+0

你会帮助我吗?在小提琴如果你不介意请 – medo

+0

没有人可以帮助在这件事情 – medo

相关问题