juqery ѧϰ֮Èý Ñ¡ÔñÆ÷ ²ã¼¶ »ù±¾£¬Ñ§Ï°jqueryµÄÅóÓÑ¿ÉÒԲο¼Ï¡£
#id
¸ù¾Ý¸ø¶¨µÄIDÆ¥ÅäÒ»¸öÔªËØ¡£
Matches a single element with the given id attribute.
·µ»ØÖµ
Element
²ÎÊý
id (String) : ÓÃÓÚËÑË÷µÄ£¬Í¨¹ýÔªËØµÄ id ÊôÐÔÖиø¶¨µÄÖµ
ʾÀý
²éÕÒ ID Ϊ"myDiv"µÄÔªËØ¡£
HTML ´úÂë:
<div id="notMe"><p>id="notMe"</p></div> <div id="myDiv">id="myDiv"</div>
jQuery ´úÂë:
$("#myDiv");
½á¹û:
[ <div id="myDiv">id="myDiv"</div> ] ---------------------------------------------------------------------------------------
element
¸ù¾Ý¸ø¶¨µÄÔªËØÃûÆ¥ÅäËùÓÐÔªËØ
Matches all elements with the given name.
·µ»ØÖµ
Array<Element>
²ÎÊý
element (String) : Ò»¸öÓÃÓÚËÑË÷µÄÔªËØ¡£Ö¸Ïò DOM ½ÚµãµÄ±êÇ©Ãû¡£
ʾÀý
²éÕÒÒ»¸ö DIV ÔªËØ¡£
HTML ´úÂë:
<div>DIV1</div> <div>DIV2</div> <span>SPAN</span>
jQuery ´úÂë:
$("div");
½á¹û:
[ <div>DIV1</div>, <div>DIV2</div> ] ---------------------------------------------------------------------------------------
.class
¸ù¾Ý¸ø¶¨µÄÀàÆ¥ÅäÔªËØ¡£
Matches all elements with the given class.
·µ»ØÖµ
Array<Element>
²ÎÊý
class (String) : Ò»¸öÓÃÒÔËÑË÷µÄÀà¡£Ò»¸öÔªËØ¿ÉÒÔÓжà¸öÀֻ࣬ҪÓÐÒ»¸ö·ûºÏ¾ÍÄܱ»Æ¥Åäµ½¡£
ʾÀý
²éÕÒËùÓÐÀàÊÇ "myClass" µÄÔªËØ.
HTML ´úÂë:
<div class="notMe">div class="notMe"</div> <div class="myClass">div class="myClass"</div> <span class="myClass">span class="myClass"</span>
jQuery ´úÂë:
$(".myClass");
½á¹û:
[ <div class="myClass">div class="myClass"</div>, <span class="myClass">span class="myClass"</span> ] ---------------------------------------------------------------------------------------
*
Æ¥ÅäËùÓÐÔªËØ
¶àÓÃÓÚ½áºÏÉÏÏÂÎÄÀ´ËÑË÷¡£
Matches all elements.
Most useful when combined with a context to search in.
·µ»ØÖµ
Array<Element>
ʾÀý
ÕÒµ½Ã¿Ò»¸öÔªËØ
HTML ´úÂë:
<div>DIV</div> <span>SPAN</span> <p>P</p>
jQuery ´úÂë:
$("*")
½á¹û:
[ <div>DIV</div>, <span>SPAN</span>, <p>P</p> ] ---------------------------------------------------------------------------------------
selector1,selector2,selectorN
½«Ã¿Ò»¸öÑ¡ÔñÆ÷Æ¥Åäµ½µÄÔªËغϲ¢ºóÒ»Æ𷵻ء£
Äã¿ÉÒÔÖ¸¶¨ÈÎÒâ¶à¸öÑ¡ÔñÆ÷£¬²¢½«Æ¥Åäµ½µÄÔªËغϲ¢µ½Ò»¸ö½á¹ûÄÚ¡£
Matches the combined results of all the specified selectors.
You can specify any number of selectors to combine into a single result.
·µ»ØÖµ
Array<Element>
²ÎÊý
selector1 (Selector) : Ò»¸öÓÐЧµÄÑ¡ÔñÆ÷
selector2 (Selector) : ÁíÒ»¸öÓÐЧµÄÑ¡ÔñÆ÷
selectorN (Selector) : (¿ÉÑ¡) ÈÎÒâ¶à¸öÓÐЧѡÔñÆ÷
ʾÀý
ÕÒµ½Æ¥ÅäÈÎÒâÒ»¸öÀàµÄÔªËØ¡£
HTML ´úÂë:
<div>div</div> <p class="myClass">p class="myClass"</p> <span>span</span> <p class="notMyClass">p class="notMyClass"</p>
jQuery ´úÂë:
$("div,span,p.myClass")
½á¹û:
[ <div>div</div>, <p class="myClass">p class="myClass"</p>, <span>span</span> ] ---------------------------------------------------------------------------------------
ancestor descendant
ÔÚ¸ø¶¨µÄ×æÏÈÔªËØÏÂÆ¥ÅäËùÓеĺó´úÔªËØ
Matches all descendant elements specified by descendant of elements specified by ancestor.
·µ»ØÖµ
Array<Element>
²ÎÊý
ancestor (Selector) : ÈκÎÓÐЧѡÔñÆ÷
descendant (Selector) : ÓÃÒÔÆ¥ÅäÔªËصÄÑ¡ÔñÆ÷£¬²¢ÇÒËüÊǵÚÒ»¸öÑ¡ÔñÆ÷µÄºó´úÔªËØ
ʾÀý
ÕÒµ½±íµ¥ÖÐËùÓÐµÄ input ÔªËØ
HTML ´úÂë:
<form> <label>Name:</label> <input name="name" /> <fieldset> <label>Newsletter:</label> <input name="newsletter" /> </fieldset> </form> <input name="none" />
jQuery ´úÂë:
$("form input")
½á¹û:
[ <input name="name" />, <input name="newsletter" /> ] ---------------------------------------------------------------------------------------
parent > child
ÔÚ¸ø¶¨µÄ¸¸ÔªËØÏÂÆ¥ÅäËùÓеÄ×ÓÔªËØ
Matches all child elements specified by child of elements specified by parent.
·µ»ØÖµ
Array<Element>
²ÎÊý
parent (Selector) : ÈκÎÓÐЧѡÔñÆ÷
child (Selector) : ÓÃÒÔÆ¥ÅäÔªËصÄÑ¡ÔñÆ÷£¬²¢ÇÒËüÊǵÚÒ»¸öÑ¡ÔñÆ÷µÄ×ÓÔªËØ
ʾÀý
Æ¥Åä±íµ¥ÖÐËùÓеÄ×Ó¼¶inputÔªËØ¡£
HTML ´úÂë:
<form> <label>Name:</label> <input name="name" /> <fieldset> <label>Newsletter:</label> <input name="newsletter" /> </fieldset> </form> <input name="none" />
jQuery ´úÂë:
$("form > input")
½á¹û:
[ <input name="name" /> ] ---------------------------------------------------------------------------------------
prev + next
Æ¥ÅäËùÓнô½ÓÔÚ prev ÔªËغóµÄ next ÔªËØ
Matches all next elements specified by next that are next to elements specified by prev.
·µ»ØÖµ
Array<Element>
²ÎÊý
prev (Selector) : ÈκÎÓÐЧѡÔñÆ÷
next (Selector) :Ò»¸öÓÐЧѡÔñÆ÷²¢ÇÒ½ô½Ó×ŵÚÒ»¸öÑ¡ÔñÆ÷
ʾÀý
Æ¥ÅäËùÓиúÔÚ label ºóÃæµÄ input ÔªËØ
HTML ´úÂë:
<form> <label>Name:</label> <input name="name" /> <fieldset> <label>Newsletter:</label> <input name="newsletter" /> </fieldset> </form> <input name="none" />
jQuery ´úÂë:
$("label + input")
½á¹û:
[ <input name="name" />, <input name="newsletter" /> ] ---------------------------------------------------------------------------------------
prev ~ siblings
Æ¥Åä prev ÔªËØÖ®ºóµÄËùÓÐ siblings ÔªËØ
Matches all sibling elements after the "prev" element that match the filtering "siblings" selector.
·µ»ØÖµ
Array<Element>
²ÎÊý
prev (Selector) : ÈκÎÓÐЧѡÔñÆ÷
siblings (Selector) : Ò»¸öÑ¡ÔñÆ÷£¬²¢ÇÒËü×÷ΪµÚÒ»¸öÑ¡ÔñÆ÷µÄͬ±²
ʾÀý
ÕÒµ½ËùÓÐÓë±íµ¥Í¬±²µÄ input ÔªËØ
HTML ´úÂë:
<form> <label>Name:</label> <input name="name" /> <fieldset> <label>Newsletter:</label> <input name="newsletter" /> </fieldset> </form> <input name="none" />
jQuery ´úÂë:
$("form ~ input")
½á¹û:
[ <input name="none" /> ]
|