我需要将项目移动到不同的div中(因此用户可以选择他们最喜欢的),但是我需要原始列表始终具有3的切片,因为它将在滑块中。因此,当一个项目被移动到选定框时,非选定框总是保留一个li标签,其中包含3个锚
这是我的小提琴http://jsfiddle.net/8VrdE/308/这是我的js
var threelist = $("ul#nonSelected > a");
for(var i = 0; i < threelist.length; i+=3) {
threelist.slice(i, i+3).wrapAll("<li class='new'></li>");
}
function moveButton(elem) {
if ($(elem).parent().parent().attr("id") == "nonSelected") {
$(elem).detach().appendTo('#selected');
} else {
$(elem).detach().appendTo('#nonSelected');
}
}
改变功能
function moveButton(elem) {
if ($(elem).closest('ul').attr("id") == "nonSelected") {
$(elem).detach().appendTo('#selected');
} else {
$(elem).detach().appendTo(
// slice parent
'#nonSelected '
// slice
+ 'li'
// dose not have 3 anchors
+ ':not(:has(a:eq(2)))'
// select first slice(not have 3 a)
+ ':first'
);
// base selector
// '#nonSelected li:not(:has(a:eq(2))):first'
}
}