gpt4 book ai didi

javascript 移动按钮并放入切片

转载 作者:行者123 更新时间:2023-12-03 06:04:55 26 4
gpt4 key购买 nike

我需要将项目移动到不同的 div 中(以便用户可以选择他们最喜欢的项目),但是我需要原始列表始终有 3 个切片,因为它将位于 slider 中。因此,当一个项目移动到选定的框时,未选定的框始终保留一个 li 标签,其中包含 3 个 anchor

这是我的 fiddle 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'
}
}

关于javascript 移动按钮并放入切片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39593069/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com