jquery - 如何将LI元素从一个UL切换到另一个UL [英] jquery - how to CUT LI elements from one UL to another UL

查看:110
本文介绍了jquery - 如何将LI元素从一个UL切换到另一个UL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一些LI从一个UL复制到另一个UL。

I would like to copy some LI's from one UL to another UL.

在我的第一个UL中,我有10个LI,我想要削减6,7, 8,9,10到另一个div。
我如何在jQuery中实现它?

In my first UL I have 10 LI's and I would like to CUT 6,7,8,9,10 to another div. How do I achieve it in jQuery ?

推荐答案

你可以使用 .slice [docs] .appendTo [ docs]

You can do these easily with .slice [docs] and .appendTo [docs]:

$('#list1 > li').slice(5,10).appendTo('#list2');
// or to the end of list: 
// $('#list1 > li').slice(5).appendTo('#list2');

这将移动列表元素到另一个列表。如果您想复制,请添加 .clone [docs]

This will move the list elements to the other list. If you want to copy them, add .clone [docs].

如果要移动非连续列表元素,你必须以不同的方式选择它们。

If you want to move non-consecutive list elements, you have to select them differently.

这篇关于jquery - 如何将LI元素从一个UL切换到另一个UL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆