原型选择器:简单示例 [英] Prototype Selector : simple examples
问题描述
我在互联网上找不到简单的例子:
- 选择页面上具有相同id的所有元素
(我这样做,但它只适用于第一个元素:$('mydiv')。hide()
) - 选择由其id包含在另一个div中的div。
- 隐藏具有myClass类的所有元素。
在一个页面上多次拥有相同的ID。除了违反标准,它是一个潜在的问题的食谱,因为你不知道你的JavaScript将如何反应。
在页面上选择具有相同
id'm做这个,但
仅适用于第一个元素:
$('mydiv')。hide())
使用 $$
:
.myclass')
选择$ b $中包含的div
使用 $$
:
$$('div#outer div#inner')
隐藏所有具有myClass
类的元素。
$ b b
使用 $$
, each()
和 hide code>
$$('。myClass')。each(function(d){
.hide();
});
$$
是您的朋友。
i'm just starting prototype, i was on jquery before.
I can't find easy examples on the internet about how :
- Selecting all elements having the same id on a page
(I'm doing this but it only works for the first element :
$('mydiv').hide()
) - Selecting a div that is contained in another div by their id.
- hiding all elements that have myClass class.
As mentioned above you shouldn't have the same ID on a page more then once. Besides being against standards it's a recipe for potential problems since you don't know how your JavaScript will react to it. Uses classes instead.
Selecting all elements having the same
idclass on a page (i'm doing this but it only works for the first element : $('mydiv').hide() )
Use $$
:
$$('.myclass')
Selecting a div that is contained in another div by their id.
Use $$
:
$$('div#outer div#inner')
hiding all elements that have myClass class.
Use $$
, each()
, and hide()
$$('.myClass').each(function(d) {
d.hide();
});
$$
is your friend.
这篇关于原型选择器:简单示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!