如何在单个语句中对 $$('selector') 数组使用 PrototypeJS .wrap()?
How to use PrototypeJS .wrap() on a $$('selector') array in a single statement?
来自 jQuery 背景到使用 PrototypeJS 的项目。
$('someId');
在 PrototypeJS 中 will return the element with the given id。
$$('ul.someClass li');
将 return 匹配 CSS 选择器的元素,但在 a document-ordered array.
我怎么能运行 wrap()
on the elements in the console, on a single line, since the iterator
argument on each()
需要一个只接受一个集合元素和一个索引的函数。
使用 Enumerable#invoke 方法将您的方法和参数应用于集合。刚刚尝试了以下方法,第一次尝试就成功了:
$$('p').invoke('wrap', 'div', {className: 'foo'});
来自 jQuery 背景到使用 PrototypeJS 的项目。
$('someId');
在 PrototypeJS 中 will return the element with the given id。
$$('ul.someClass li');
将 return 匹配 CSS 选择器的元素,但在 a document-ordered array.
我怎么能运行 wrap()
on the elements in the console, on a single line, since the iterator
argument on each()
需要一个只接受一个集合元素和一个索引的函数。
使用 Enumerable#invoke 方法将您的方法和参数应用于集合。刚刚尝试了以下方法,第一次尝试就成功了:
$$('p').invoke('wrap', 'div', {className: 'foo'});