2017-04-18 26 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

相關問題