Ric*_*ham 3 javascript mootools
Mootools可以淡化匹配选择器的所有节点,如下所示:
$$('#div img').fade(0.3);
Run Code Online (Sandbox Code Playgroud)
我需要一种跳过特定节点的方法.在jQuery-world中,我使用not(),它会是这样的:
$$('#div img').not( oneElement ).fade(0.3);
Run Code Online (Sandbox Code Playgroud)
但我找不到任何方式在mootools中表现出类似的行为.谁知道什么?
在html元素集合上使用.filter将具有相同的效果,前提是oneElement是一个合适的对象:
$$("img").filter(function(el) {
return el !== oneElement;
}).fade(.3);
Run Code Online (Sandbox Code Playgroud)
为了演示多功能的mootools,这里是你如何模仿你已经知道的语法:
Array.implement({
not: function(skipEl) {
return skipEl ? this.filter(function(el) {
return el !== skipEl;
}) : this;
}
});
var divs = document.getElements("div");
var redDiv = document.getElement("div.red");
divs.not(redDiv).fade(.2);
Run Code Online (Sandbox Code Playgroud)
在这里看到这个:http://www.jsfiddle.net/dimitar/Z9MNe/
标记:
<div ></div>
<div ></div>
<div ></div>
<div class="red" ></div>
<div ></div>
Run Code Online (Sandbox Code Playgroud)
正如FunFactor在irc上指出的那样,你只能使用选择器来获得你想要的东西:
$$('div.something:not(#someId)')会工作,但如果您只是处理一个对象,例如this在onClick事件上,则不会.
| 归档时间: |
|
| 查看次数: |
195 次 |
| 最近记录: |