juqery 學(xué)習(xí)之三 選擇器 子元素與表單
:nth-child(index/even/odd/equation)
可以使用:
nth-child(even)
:nth-child(odd)
:nth-child(3n)
:nth-child(2)
:nth-child(3n+1)
:nth-child(3n+2)
返回值
Array<Element>
參數(shù)
index (Number) : 要匹配元素的序號,從1開始
示例
在每個 ul 查找第 2 個li
HTML 代碼:
<li>John</li>
<li>Karl</li>
<li>Brandon</li>
</ul>
<ul>
<li>Glen</li>
<li>Tane</li>
<li>Ralph</li>
</ul>
jQuery 代碼:
結(jié)果:
--------------------------------------------------------------------------------
:first-child
返回值
Array<Element>
示例
在每個 ul 中查找第一個 li
HTML 代碼:
<li>John</li>
<li>Karl</li>
<li>Brandon</li>
</ul>
<ul>
<li>Glen</li>
<li>Tane</li>
<li>Ralph</li>
</ul>
jQuery 代碼:
結(jié)果:
--------------------------------------------------------------------------------
:last-child
返回值
Array<Element>
示例
在每個 ul 中查找最后一個 li
HTML 代碼:
<li>John</li>
<li>Karl</li>
<li>Brandon</li>
</ul>
<ul>
<li>Glen</li>
<li>Tane</li>
<li>Ralph</li>
</ul>
jQuery 代碼:
結(jié)果:
--------------------------------------------------------------------------------
:only-child
返回值
Array<Element>
示例
在 ul 中查找是唯一子元素的 li
HTML 代碼:
<li>John</li>
<li>Karl</li>
<li>Brandon</li>
</ul>
<ul>
<li>Glen</li>
jQuery 代碼:
結(jié)果:
--------------------------------------------------------------------------------
:input
返回值
Array<Element>
示例
查找所有的input元素
HTML 代碼:
<input type="text" />
<input type="checkbox" />
<input type="radio" />
<input type="image" />
<input type="file" />
<input type="submit" />
<input type="reset" />
<input type="password" />
<input type="button" />
<select><option/></select>
<textarea></textarea>
<button></button>
</form>
jQuery 代碼:
結(jié)果:
--------------------------------------------------------------------------------
:text
返回值
Array<Element>
示例
查找所有文本框
HTML 代碼:
<input type="text" />
<input type="checkbox" />
<input type="radio" />
<input type="image" />
<input type="file" />
<input type="submit" />
<input type="reset" />
<input type="password" />
<input type="button" />
<select><option/></select>
<textarea></textarea>
<button></button>
</form>
jQuery 代碼:
結(jié)果:
--------------------------------------------------------------------------------
:password
返回值
Array<Element>
示例
查找所有密碼框
HTML 代碼:
<input type="text" />
<input type="checkbox" />
<input type="radio" />
<input type="image" />
<input type="file" />
<input type="submit" />
<input type="reset" />
<input type="password" />
<input type="button" />
<select><option/></select>
<textarea></textarea>
<button></button>
</form>
jQuery 代碼:
結(jié)果:
--------------------------------------------------------------------------------
:radio
返回值
Array<Element>
示例
查找所有單選按鈕
HTML 代碼:
<input type="text" />
<input type="checkbox" />
<input type="radio" />
<input type="image" />
<input type="file" />
<input type="submit" />
<input type="reset" />
<input type="password" />
<input type="button" />
<select><option/></select>
<textarea></textarea>
<button></button>
</form>
jQuery 代碼:
結(jié)果:
--------------------------------------------------------------------------------
:submit
返回值
Array<Element>
示例
查找所有提交按鈕
HTML 代碼:
<input type="text" />
<input type="checkbox" />
<input type="radio" />
<input type="image" />
<input type="file" />
<input type="submit" />
<input type="reset" />
<input type="password" />
<input type="button" />
<select><option/></select>
<textarea></textarea>
<button></button>
</form>
jQuery 代碼:
結(jié)果:
其他的一些 都是一樣的道理:image ,:reset,:button,:file,:hidden !@#@!%$%
相關(guān)文章
jQuery實現(xiàn)異步獲取json數(shù)據(jù)的2種方式
這篇文章主要介紹了jQuery實現(xiàn)異步獲取json數(shù)據(jù)的2種方式,主要講述了$.getJSON方法與$.ajax方法,非常實用,需要的朋友可以參考下2014-08-08
使用jQuery給input標(biāo)簽設(shè)置默認(rèn)值
這篇文章主要介紹使用jQuery給input標(biāo)簽設(shè)置默認(rèn)值的方法,實例講解,非常實用,需要的朋友可以參考下。2016-06-06
jQuery中借助deferred來請求及判斷AJAX加載的實例講解
deferred對象的延遲功能對jQuery的ajax操作是一個很大的幫助,尤其是回調(diào)控制,下面我們就來看一下對jQuery中借助deferred來請求及判斷AJAX加載的實例講解2016-05-05
jQuery基于ajax實現(xiàn)帶動畫效果無刷新柱狀圖投票代碼
這篇文章主要介紹了jQuery基于ajax實現(xiàn)帶動畫效果無刷新柱狀圖投票代碼,通過使用jquery動態(tài)操作頁面元素樣式屬性實現(xiàn)柱狀圖投票效果,非常具有實用價值,需要的朋友可以參考下2015-08-08
jQuery EasyUI 中文API Button使用實例
jQuery EasyUI 中文API Button使用小結(jié),需要的朋友可以參考下。2010-04-04

