abstrakt:具有以下特點(diǎn) :(1)基本格式$('');(2)冒號(hào),div:first,類似css偽類,通常是一種內(nèi)置方法;(3)[]方括號(hào),input[type!=text],表示屬性+值;可前置標(biāo)簽限制選擇范圍;(4){}花括號(hào),$('div').css({'color':'red','font-size':'30px&
具有以下特點(diǎn) :
(1)基本格式$('');
(2)冒號(hào),div:first,類似css偽類,通常是一種內(nèi)置方法;
(3)[]方括號(hào),input[type!=text],表示屬性+值;可前置標(biāo)簽限制選擇范圍;
(4){}花括號(hào),$('div').css({'color':'red','font-size':'30px'}),用于設(shè)置多個(gè)樣式。
jQuery的選擇器比較豐富,大體分為幾種類型:
(1)基本選擇器
$('div') $('.className') $('#idName') //設(shè)置多個(gè)樣式 $('div').css({'color':'red','font-size':'30px'}) //花括號(hào),逗號(hào)分隔鍵值對(duì)
(2)層級(jí)選擇器
$('ul>li') $('ul li') $('label+input') //緊跟label后的第一個(gè)input,如果input前沒有l(wèi)abel則不會(huì)被選中 $('label~input') //label后所有同級(jí)input
(3)順序選擇器
$('div:first') $('div:last') $('p:gt(x)') //索引大于x的p標(biāo)簽 $('p:lt(x)') //索引小于x $('p:eq(x)') //等于x $('li:odd') //索引為偶數(shù) $('li:even') //索引為奇數(shù) $('li:not(eq(x))) //非
(4)內(nèi)容選擇器
$('p:contains(text)') //內(nèi)容包含文本“text”的p標(biāo)簽 $('div:has(span)') //has(選擇器),基礎(chǔ)選擇器適用;div下的span,還是含有span的div??? //$('div:has(span)').css('color','blue')會(huì)讓div內(nèi)所有內(nèi)容變色。 $('div:empty') //既無內(nèi)容又無下級(jí)子標(biāo)簽的div $('div:parent') //有內(nèi)容或者子標(biāo)簽其中之一
(5)屬性選擇器
$('[type]') //有type屬性的所有標(biāo)簽,屬性值可以為空 $('input[type=password]') //[屬性=值]要包含在方括號(hào)內(nèi) $('input[type != password]') //不等于指定值 $('[name^=n]') //以指定值開始 $('[name$=n]') //結(jié)尾 $('[name*=n]') //包含 $('input[type=text][id][name^=n]').css('height','25px') //同時(shí)滿足多個(gè)條件 //id可以為空,但必須有該標(biāo)識(shí);方括號(hào)之間不能有空格;比較符號(hào)可以有空格。
(1)表單選擇器
$(':enabled') //相對(duì)disabled而言,激活的元素 $(':disabled') //行間設(shè)置了disabled="disabled",只有一個(gè)值,禁用 input 元素 $(':selected') //針對(duì)設(shè)置了selected的option $(':checked') //激活的checkbox【測(cè)試未成功】 //下拉框 <select name="" id=""> <option value="">react</option> <option value="">angular</option> <option value="" selected>vue</option> </select>
END
Korrigierender Lehrer:韋小寶Korrekturzeit:2018-11-10 11:11:03
Zusammenfassung des Lehrers:嗯!寫的很不錯(cuò)!很完整啊!繼續(xù)加油哈!??!