jQuery UI、排序表和具有多个列表的Cookie插件
我使用jQueryUISortable插件和cookie插件来设置和获取两个可排序列表的列表 我发现这段代码用于设置和获取cookie: 对于一个列表,而不是两个列表,它可以按照我的意愿工作(我已经对注释中列出的内容进行了更改,但在某些地方失败了) 我的猜测是,我必须为setSelector指定第一个和第二个列表,而不是为列表使用类。我尝试了“var setSelector=“#first,#second”;但这不起作用 想法 谢谢 $(函数(){jQuery UI、排序表和具有多个列表的Cookie插件,jquery,jquery-ui,cookies,jquery-ui-sortable,Jquery,Jquery Ui,Cookies,Jquery Ui Sortable,我使用jQueryUISortable插件和cookie插件来设置和获取两个可排序列表的列表 我发现这段代码用于设置和获取cookie: 对于一个列表,而不是两个列表,它可以按照我的意愿工作(我已经对注释中列出的内容进行了更改,但在某些地方失败了) 我的猜测是,我必须为setSelector指定第一个和第二个列表,而不是为列表使用类。我尝试了“var setSelector=“#first,#second”;但这不起作用 想法 谢谢 $(函数(){ //设置列表选择器 var setSelect
//设置列表选择器
var setSelector=“.sortable”;
//设置cookie名称
var setCookieName=“listOrder”;
//设置cookie到期时间(天):
var setcookieexpire=7;
//将列表顺序写入cookie的函数
函数getOrder(){
//将自定义订单保存到cookie
$.cookie(setCookieName,$(setSelector).sortable(“toArray”),{expires:setCookieExpire,路径:“/”});
}
//从cookie恢复列表顺序的函数
函数restoreOrder(){
变量列表=$(设置选择器);
if(list==null)返回
//获取cookie值(保存的顺序)
var cookie=$.cookie(setCookieName);
如果(!cookie)返回;
//从保存的顺序生成数组
var id=cookie.split(“,”);
//获取当前订单
var项目=列表可排序(“toArray”);
//从当前订单生成数组
var rebuild=新数组();
对于(var v=0,len=items.length;v您应该替换代码
var setSelector=“.sortable”
到
var setSelector=“#可排序”
您应该替换代码
var setSelector=“.sortable”
到
var setSelector=“#可排序”
_http://code.google.com/p/cookies/
_http://noteskeeper.ru/article/save-state-jquery-ui-sortable/
root = $("#sidebar");
$('> *', root).each(function (index) {
this.id = 'block-' + index;
});
root.sortable({
cursor: 'move',
revert: true,
placeholder: 'ui-state-highlight'
});
// function that writes the list order to a cookie
root.bind( "sortupdate", function (event, ui) {
// save custom order to cookie
var order = $(this).sortable('serialize');
$.cookies.set('sortable', order);
});
// here, we reload the saved order
// fetch the cookie value (saved order)
var c = $.cookies.get('sortable');
if (c) {
// function that restores the list order from a cookie
$.each(c.split('&'), function () {
var id = this.replace('[]=', '-');
$('#' + id).appendTo(root);
});
}
_http://code.google.com/p/cookies/
_http://noteskeeper.ru/article/save-state-jquery-ui-sortable/
root = $("#sidebar");
$('> *', root).each(function (index) {
this.id = 'block-' + index;
});
root.sortable({
cursor: 'move',
revert: true,
placeholder: 'ui-state-highlight'
});
// function that writes the list order to a cookie
root.bind( "sortupdate", function (event, ui) {
// save custom order to cookie
var order = $(this).sortable('serialize');
$.cookies.set('sortable', order);
});
// here, we reload the saved order
// fetch the cookie value (saved order)
var c = $.cookies.get('sortable');
if (c) {
// function that restores the list order from a cookie
$.each(c.split('&'), function () {
var id = this.replace('[]=', '-');
$('#' + id).appendTo(root);
});
}