简体   繁体   中英

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. I see alot of site coming up with Javascript stuff, but its usually saying things like save an inputted name and such. 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 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 &raquo;</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. You're best storing it on the server or using local storage.

根据排列的数量,您可以在jquery代码中创建key-> value对的哈希,其中每个值将是div的顺序,而键将是您存储在cookie中的内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM