jQuery insertAt [英] jQuery insertAt

查看:80
本文介绍了jQuery insertAt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jQuery将li元素插入ul元素的特定索引中.我似乎只能在列表末尾插入一个元素.我对jQuery非常陌生,所以我可能只是在想不通.

I'm trying to insert an li element into a specific index on a ul element using jQuery. I only seem to be able to insert an element on the end of the list. I am very new to jQuery, so I may just not be thinking properly.

推荐答案

尝试如下操作:

$("#thelist li").eq(3).after("<li>A new item</li>");

使用eq函数,您可以获取所检索元素的特定索引...然后,在其后插入新列表项.

With the eq function, you can get a specific index of the elements retrieved...then, insert the new list item after it.

在上述功能中,我将在位置4(索引3)处插入一个新项.

In the above function, I am inserting a new item at position 4 (index 3).

有关该功能的更多信息,请参见 jQuery文档

More info about the function at the jQuery Docs

这篇关于jQuery insertAt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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