Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何删除Cookie并将元素设置为再次显示?_Javascript_Jquery_Html_Cookies - Fatal编程技术网

Javascript 如何删除Cookie并将元素设置为再次显示?

Javascript 如何删除Cookie并将元素设置为再次显示?,javascript,jquery,html,cookies,Javascript,Jquery,Html,Cookies,我需要一个jQuery代码,而不是JavaScript,它将删除cookie并设置元素以再次显示 这是我的密码: HTML: <div class="recoverit"><a href="javascript:;">Recover Cookies</a></div> 存储cookies非常有效,但现在我需要删除它们和“elementId”以在相同的位置再次显示 谢谢。你可以试试这个: function delete_cookie(element

我需要一个jQuery代码,而不是JavaScript,它将删除cookie并设置元素以再次显示

这是我的密码:

HTML:

<div class="recoverit"><a href="javascript:;">Recover Cookies</a></div>
存储cookies非常有效,但现在我需要删除它们和“elementId”以在相同的位置再次显示

谢谢。

你可以试试这个:

function delete_cookie(elementId) {
    document.cookie = elementId + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
};
或者,您也可以按照其他人的建议使用jquery

按要求更新完整样本:

<html>
<script>
function setCookie(elementId) {
    document.cookie = elementId + "=true; path=/; expires=Th, 31 Dec 2099 11:00:00 GMT;";
    document.getElementById(elementId).style.display = "none";
}

function deleteCookie(elementId) {
    document.cookie = elementId + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
    document.getElementById(elementId).style.display = "block";
}
</script>
<body>
<a href="#" onclick="setCookie('el1');">hide element</a>

<a href="#" onclick="deleteCookie('el1');">restore element</a>

<br>
<div id="el1">one two three...</div>
</body>
</html>

函数setCookie(elementId){
document.cookie=elementId+“=true;path=/;expires=Th,2009年12月31日11:00:00 GMT;”;
document.getElementById(elementId).style.display=“无”;
}
函数deleteCookie(elementId){
document.cookie=elementId+'=;expires=Thu,1970年1月1日00:00:01 GMT;';
document.getElementById(elementId).style.display=“block”;
}

一二三。。。
jQuery是JavaScriptI,我知道,但我在jQuery中需要它。
document.cookie
不是jQuery。是否尝试在jQuery cookie上读取文档?我不想使用任何插件。。我将尝试此操作,但如何设置元素以在不刷新的情况下再次显示?他要求提供jquery soloutiondocument.getElementById(elementId).style.display='block'无jquery$('#elementId').show()jquery@Ra3IDeN但它也不想要插件。降级我的答案是不正确的,因为即使你有jquery.Jkike,它也能工作,你能详细说明一下吗?谢谢
<html>
<script>
function setCookie(elementId) {
    document.cookie = elementId + "=true; path=/; expires=Th, 31 Dec 2099 11:00:00 GMT;";
    document.getElementById(elementId).style.display = "none";
}

function deleteCookie(elementId) {
    document.cookie = elementId + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
    document.getElementById(elementId).style.display = "block";
}
</script>
<body>
<a href="#" onclick="setCookie('el1');">hide element</a>

<a href="#" onclick="deleteCookie('el1');">restore element</a>

<br>
<div id="el1">one two three...</div>
</body>
</html>