gpt4 book ai didi

javascript - jquery 中的 mootools 双美元等价物

转载 作者:行者123 更新时间:2023-11-30 13:24:12 25 4
gpt4 key购买 nike

我有一行代码使用 mootools 获取具有给定选择器的元素数组

var menuItems =  $$('#container .menu');

我需要将其转换为 jquery,但找不到解决方案。我试过 jQuery('#container .menu') 但它没有返回数组。

有没有办法在整个文档中使用 jquery 中的“.find()”? (因为我没有父元素来使它像 parent.find()..)

也欢迎大家提出其他建议

最佳答案

使用 jQuery 你的语句:

jQuery('#container .menu')

将返回一个包含所有匹配元素的 jQuery 对象,您可以在其中使用类似数组的语法访问各个 DOM 元素:

var menuItems = jQuery('#container .menu');

menuItems.length // gives a count of how many matched
menuItems[0] // the first matching element

// but you can also use jQuery methods on the object
menuItems.hide();

如果您想要一个实际的数组而不是类似数组的对象,您可以使用 jQuery 的 .toArray() method :

var menutItemsArray = jQuery('#container .menu').toArray();

你为什么不试试 one of the jQuery tutorials可在 jQuery website

关于javascript - jquery 中的 mootools 双美元等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9094690/

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