如何使用 Prototype 复制 YUI 的 getElementsBy?
我正在将一些代码从 YUI 移动到 javascript,其中一些代码使用 YUI 的 YAHOO.util.Dom.getElementsBy(function)。我一直在阅读原型 API 文档,但未能找到等效的内容。它需要能够接受任意函数,而不仅仅是选择 CSS 选择器等。谁能向我建议在原型中完成此任务的最佳方法?
I'm moving some code from YUI to javascript and some of it is using YUI's YAHOO.util.Dom.getElementsBy(function). I've been reading through the prototype API docs and haven't been able to find something equivalent. It needs to be able to take an arbitrary function not just select off a CSS selector or the like. Can anyone suggest to me the best way to accomplish this in Prototype?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用美元兑美元函数和过滤函数:
You can use the dollar-dollar function and the filter function :
Jack Sleight 的函数,来自 http://www.codingforums.com/showthread.php? t=83993 基于 getElementsByClassName ,它按原样完成我所需要的,并且可以轻松扩展以采用任意函数:
A function by Jack Sleight from http://www.codingforums.com/showthread.php?t=83993 based on getElementsByClassName that accomplishes what I need as is and would be easily extended to take an arbitrary function: