调用指定索引的子级?

发布于 2024-09-19 20:02:12 字数 119 浏览 1 评论 0原文

有人知道编写此语句的正确语法吗?

$('.nav ul li')[0].children("a")

由于某种原因,这不起作用。返回的是它不是一个函数。 :(

Anyone know the proper syntax to write this statement?

$('.nav ul li')[0].children("a")

For some reason this is not working. The return is that its not a function. :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧时浪漫 2024-09-26 20:02:22

您可以尝试从结果中获取第一个元素。

$('.nav ul li').first().children("a")

或者,如果您需要特定索引,

$('.nav ul li').eq(0).children("a")

您也可以根据需要使用选择器 :eq(n):first

You can try this for getting the first element from the results.

$('.nav ul li').first().children("a")

Or if you need a specific index

$('.nav ul li').eq(0).children("a")

You can also use the selectors :eq(n) and :first if you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文