JQuery每天函数:核心 jQuery(express
发布时间: 2012-11-05 09:35:12 作者: rapoo
JQuery每日函数:核心 jQuery(expression,[context])
?
jQuery(expression,[context])
The core functionality of jQuery centers around this function. Everything in jQuery is based upon this, or uses this in some way. The most basic use of this function is to pass in an expression (usually consisting of CSS), which then finds all matching elements.
By default, if no context is specified, $() looks for DOM elements within the context of the current HTML document. If you do specify a context, such as a DOM element or jQuery object, the expression will be matched against the contents of that context.
See Selectors for the allowed CSS syntax for expressions.
返回值
jQuery
参数
expression (String) : 用来查找的字符串
context (Element, jQuery) : (可选) 作为待查找的 DOM 元素集、文档或 jQuery 对象。
示例
找到所有 p 元素,并且这些元素都必须是 div 元素的子元素。
HTML 代码:
<p>one</p> <div><p>two</p></div> <p>three</p>
jQuery 代码:
$("div > p");
结果:
[ <p>two</p> ]
在文档的第一个表单中,查找所有的单选按钮(即: type 值为 radio 的 input 元素)。
jQuery 代码:
$("input:radio", document.forms[0]);
在一个由 AJAX 返回的 XML 文档中,查找所有的 div 元素。
jQuery 代码:
$("div", xml.responseXML);