[英]How would I make a cookie to save the position of these div tags?
I am using JQuery to have the ability to reorder my divs (code below), but I need to make a cookie to save the order of these divs. 我正在使用JQuery来对div进行重新排序(下面的代码),但是我需要制作一个cookie来保存这些div的顺序。 I see alot of site coming up with Javascript stuff, but its usually saying things like save an inputted name and such.
我看到很多站点都在编写Javascript内容,但是它通常会说诸如保存输入名称之类的内容。 I have no clue how to go about doing this.
我不知道如何去做。
$().ready(function() {
$('.moveUpCls').click(function(event){
var current = $(this).parent().parent().parent();
current.prev().before(current);
});
$('.moveDownCls').click(function(){
var current = $(this).parent().parent().parent();
current.next().after(current);
});
});
Each moveable div follows this pattern (The div's also have hide/show on em, but ignore that for the time being): 每个可移动的div都遵循这种模式(div上也有em的隐藏/显示,但是暂时忽略它):
<div>
<div id="tabHeader">
<div id="headMoveUp"><a class="moveUpCls"><img src="images/uparrow.png"></a></div>
<div id="headMoveDown"><a class="moveDownCls"><img src="images/downarrow.png"></a></div>
<a href="javascript:toggle();"><div id="tabHeadText">Important Links »</div> </a>
</div>
<div id="toggleText" style="display:none; text-align:center;">
<div id="empGuide" style="text-align:center;margin-left:auto; margin-right:auto;">
CONTENT OF DIV
</div>
</div>
<br />
</div>
I'd use a JSON representation of your layout, but beware, cookies can only hold 4K of data. 我会使用布局的JSON表示形式,但是请注意,Cookie只能容纳4K数据。 You're best storing it on the server or using local storage.
最好将其存储在服务器上或使用本地存储。
根据排列的数量,您可以在jquery代码中创建key-> value对的哈希,其中每个值将是div的顺序,而键将是您存储在cookie中的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.