如何选择多个jQuery对象? [英] How to select multiple jQuery objects?
本文介绍了如何选择多个jQuery对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
就像我想要选择文档和窗口元素一样。
Like if I wanted to select both document and window elements.
$(window, document).doStuff();
不起作用。可能是因为根据文档,第二个论点是一些上下文的东西...
Doesn't work. Probably because according to the docs, 2nd argument is some "context" thing...
基本上我只是在寻找替代方案
Basically I'm just looking for an alternative too
$(window).doStuff();
$(document).doStuff();
推荐答案
var one = $("#1");
var two = $("#2");
var three = $("#3");
var four = $("#4");
$([one, two, three, four]).each(function() {
// your function here
});
文件就绪
事件在即使所有图形尚未加载,也会加载 HTML-Document
并且 DOM
已准备就绪。
The document ready
event executes already when the HTML-Document
is loaded and the DOM
is ready, even if all the graphics haven’t loaded yet.
如果你想在加载窗口之前连接某些元素的事件,那么 $(document).ready
是对的地方。
If you want to hook up your events for certain elements before the window loads, then $(document).ready
is the right place.
这篇关于如何选择多个jQuery对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文