手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >jQuery实现元素拖拽并cookie保存顺序的方法
jQuery实现元素拖拽并cookie保存顺序的方法
摘要:本文实例讲述了jQuery实现元素拖拽并cookie保存顺序的方法。分享给大家供大家参考,具体如下:div{border:1pxsolidr...

本文实例讲述了jQuery实现元素拖拽并cookie保存顺序的方法。分享给大家供大家参考,具体如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> div { border: 1px solid red; } #myList { padding-top: 20px; width: 500px; background: #EEE; list-style-type: none; } #myList li { height: 30px; cursor: pointer; margin: 20px; border: 1px solid blue; } #myList a { text-decoration: none; color: #0077B0; } #myList a:hover { text-decoration: underline; } #myList .qlink { font-size: 12px; color: #666; margin-left: 10px; } </style> <script src="jquery-1.6.2.min.js" type="text/javascript"></script> <script src="jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script> <script src="jquery.cookie.js" type="text/javascript"></script> <script type="text/javascript"> $(function() { $("#myList").sortable({ delay: 1, containment: "div",connectWith: ".otherlist", stop: function() { //alert($("#myList").sortable("serialize")); //alert($("#myList").sortable("toArray")); $.cookie("myCookie",$("#myList").sortable('toArray'),{ expires: 7 }); //alert($.cookie("myCookie")); }}); if ($.cookie("myCookie")) { var ids = $.cookie("myCookie").split(","); for (var i = 0; i < ids.length; i++) { $("#" + ids[i]).appendTo("#myList"); }} }); </script> </head> <body> <div> <ul id="myList"> <li id="myList_mood"><a href="#">心情</a> </li> <li id="myList_photo"><a href="#">相册</a> </li> <li id="myList_blog"><a href="#">日志</a> </li> <li id="myList_vote"><a href="#">投票</a> </li> <li id="myList_shate"><a href="#">分享</a> </li> <li id="myList_group"><a href="#">群组</a> </li> </ul> </div> </body> </html>

希望本文所述对大家jQuery程序设计有所帮助。

【jQuery实现元素拖拽并cookie保存顺序的方法】相关文章:

js实现两点之间画线的方法

jQuery实现转动随机数抽奖效果的方法

Jquery动态添加输入框的方法

JQuery中DOM实现事件移除的方法

jQuery实现表格行上移下移和置顶的方法

jQuery实现给页面换肤的方法

JQuery实现带排序功能的权限选择实例

JavaScript实现DIV层拖动及动态增加新层的方法

jquery实现图片左右切换的方法

jQuery实现html表格动态添加新行的方法

精品推荐
分类导航