代碼例子:某個div塊下的字型樣式的控制。

View Code
第一種:jquery條件綜合多條件選擇器
模式:$(選擇器1,選擇器2)----->傳回選擇器1内符合選擇器2的jquery對象(選擇器1内的後代元素,兒子孫子輩都有)
第二種:jquery對象find()方法
模式:$(選擇器1,選擇器2).find("選擇器3")--->傳回符合選擇器1,選擇器2的jquery對象中包含的符合選擇器3的所有後代元素。包括孫子輩。不包括自身。
第三種:jquery對象children()方法
模式:$(選擇器1,選擇器2).children("選擇器3")--->傳回符合選擇器1+選擇器2的孩子級别的選擇器3的jquery對象。隻包含孩子輩,無孫子輩。不包括自身。
選擇器
執行個體
選取
<a href="http://www.w3school.com.cn/jquery/selector_all.asp">*</a>
$("*")
所有元素
<a href="http://www.w3school.com.cn/jquery/selector_id.asp">#id</a>
$("#lastname")
id="lastname" 的元素
<a href="http://www.w3school.com.cn/jquery/selector_class.asp">.class</a>
$(".intro")
所有 class="intro" 的元素
<a href="http://www.w3school.com.cn/jquery/selector_element.asp">element</a>
$("p")
所有 <p> 元素
.class.class
$(".intro.demo")
所有 class="intro" 且 class="demo" 的元素
<a href="http://www.w3school.com.cn/jquery/selector_first.asp">:first</a>
$("p:first")
第一個 <p> 元素
<a href="http://www.w3school.com.cn/jquery/selector_last.asp">:last</a>
$("p:last")
最後一個 <p> 元素
<a href="http://www.w3school.com.cn/jquery/selector_even.asp">:even</a>
$("tr:even")
所有偶數 <tr> 元素
<a href="http://www.w3school.com.cn/jquery/selector_odd.asp">:odd</a>
$("tr:odd")
所有奇數 <tr> 元素
<a href="http://www.w3school.com.cn/jquery/selector_eq.asp">:eq(index)</a>
$("ul li:eq(3)")
清單中的第四個元素(index 從 0 開始)
<a href="http://www.w3school.com.cn/jquery/selector_gt.asp">:gt(no)</a>
$("ul li:gt(3)")
列出 index 大于 3 的元素
<a href="http://www.w3school.com.cn/jquery/selector_lt.asp">:lt(no)</a>
$("ul li:lt(3)")
列出 index 小于 3 的元素
:not(selector)
$("input:not(:empty)")
所有不為空的 input 元素
<a href="http://www.w3school.com.cn/jquery/selector_header.asp">:header</a>
$(":header")
所有标題元素 <h1> - <h6>
<a href="http://www.w3school.com.cn/jquery/selector_animated.asp">:animated</a>
所有動畫元素
<a href="http://www.w3school.com.cn/jquery/selector_contains.asp">:contains(text)</a>
$(":contains('W3School')")
包含指定字元串的所有元素
<a href="http://www.w3school.com.cn/jquery/selector_empty.asp">:empty</a>
$(":empty")
無子(元素)節點的所有元素
:hidden
$("p:hidden")
所有隐藏的 <p> 元素
<a href="http://www.w3school.com.cn/jquery/selector_visible.asp">:visible</a>
$("table:visible")
所有可見的表格
s1,s2,s3
$("th,td,.intro")
所有帶有比對選擇的元素
<a href="http://www.w3school.com.cn/jquery/selector_attribute.asp">[attribute]</a>
$("[href]")
所有帶有 href 屬性的元素
<a href="http://www.w3school.com.cn/jquery/selector_attribute_equal_value.asp">[attribute=value]</a>
$("[href='#']")
所有 href 屬性的值等于 "#" 的元素
<a href="http://www.w3school.com.cn/jquery/selector_attribute_notequal_value.asp">[attribute!=value]</a>
$("[href!='#']")
所有 href 屬性的值不等于 "#" 的元素
<a title="jQuery [attribute$=value] 選擇器" href="http://www.w3school.com.cn/jquery/selector_attribute_end_value.asp">[attribute$=value]</a>
$("[href$='.jpg']")
所有 href 屬性的值包含以 ".jpg" 結尾的元素
<a href="http://www.w3school.com.cn/jquery/selector_input.asp">:input</a>
$(":input")
所有 <input> 元素
<a href="http://www.w3school.com.cn/jquery/selector_input_text.asp">:text</a>
$(":text")
所有 type="text" 的 <input> 元素
<a href="http://www.w3school.com.cn/jquery/selector_input_password.asp">:password</a>
$(":password")
所有 type="password" 的 <input> 元素
<a href="http://www.w3school.com.cn/jquery/selector_input_radio.asp">:radio</a>
$(":radio")
所有 type="radio" 的 <input> 元素
<a href="http://www.w3school.com.cn/jquery/selector_input_checkbox.asp">:checkbox</a>
$(":checkbox")
所有 type="checkbox" 的 <input> 元素
<a href="http://www.w3school.com.cn/jquery/selector_input_submit.asp">:submit</a>
$(":submit")
所有 type="submit" 的 <input> 元素
<a href="http://www.w3school.com.cn/jquery/selector_input_reset.asp">:reset</a>
$(":reset")
所有 type="reset" 的 <input> 元素
<a href="http://www.w3school.com.cn/jquery/selector_input_button.asp">:button</a>
$(":button")
所有 type="button" 的 <input> 元素
<a href="http://www.w3school.com.cn/jquery/selector_input_image.asp">:image</a>
$(":image")
所有 type="image" 的 <input> 元素
<a href="http://www.w3school.com.cn/jquery/selector_input_file.asp">:file</a>
$(":file")
所有 type="file" 的 <input> 元素
<a href="http://www.w3school.com.cn/jquery/selector_input_enabled.asp">:enabled</a>
$(":enabled")
所有激活的 input 元素
<a href="http://www.w3school.com.cn/jquery/selector_input_disabled.asp">:disabled</a>
$(":disabled")
所有禁用的 input 元素
<a href="http://www.w3school.com.cn/jquery/selector_input_selected.asp">:selected</a>
$(":selected")
所有被選取的 input 元素
<a href="http://www.w3school.com.cn/jquery/selector_input_checked.asp">:checked</a>
$(":checked")
所有被選中的 input 元素
撒旦法