gpt4 book ai didi

javascript - 原型(prototype) 1.6.0+ 相当于 'document.getElementsByClassName' 是什么?

转载 作者:行者123 更新时间:2023-11-28 12:45:18 25 4
gpt4 key购买 nike

具体来说,我需要等效的选择器,它在 Prototype 1.5.0 中有效:

//for each element with class of 'myClassName' and an ancestor with id='myElementID'...
document.getElementsByClassName('myClassName', $('myElementID')).each( ... );

我尝试过这个:

$$('myElementID input.myClassName').each( ... ); //Because I will be selecting input elements with this class

还有这个:

$$('myElementID .myClassName').each( ... ); //Trying to get all child elements with this class name

我每次都会得到一个空列表。我想要的子元素不一定是直接子元素,所以我知道 > 字符不起作用。

我不使用 Prototype,也无法找到有关此确切问题的帮助。如有任何帮助,我们将不胜感激。

最佳答案

$$函数将接受任何 CSS 选择器,因此使用 # 通过 id 获取 myElementID。用于获取 myElementID 内的类 myClassName 的所有输入的选择器的其余部分是正确的。

$$('#myElementID input.myClassName').each( ... );

关于javascript - 原型(prototype) 1.6.0+ 相当于 'document.getElementsByClassName' 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8300485/

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