国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

juqery 學習之三 選擇器 子元素與表單

2019-11-21 00:05:25
字體:
來源:轉載
供稿:網友

:nth-child(index/even/odd/equation)

匹配其父元素下的第N個子或奇偶元素
':eq(index)' 只匹配一個元素,而這個將為每一個父元素匹配子元素。:nth-child從1開始的,而:eq()是從0算起的!

可以使用:
nth-child(even)
:nth-child(odd)
:nth-child(3n)
:nth-child(2)
:nth-child(3n+1)
:nth-child(3n+2)


Matches the nth-child of its parent.

返回值

Array<Element>

參數

index (Number) : 要匹配元素的序號,從1開始

示例

在每個 ul 查找第 2 個li

HTML 代碼:

<ul>
  <li>John</li>
  <li>Karl</li>
  <li>Brandon</li>
</ul>
<ul>
  <li>Glen</li>
  <li>Tane</li>
  <li>Ralph</li>
</ul>

jQuery 代碼:

$("ul li:nth-child(2)")

結果:

[ <li>Karl</li>,   <li>Tane</li> ]
--------------------------------------------------------------------------------

:first-child

匹配第一個子元素
':first' 只匹配一個元素,而此選擇符將為每個父元素匹配一個子元素

Matches the first child of its parent.

返回值

Array<Element>

示例

在每個 ul 中查找第一個 li

HTML 代碼:

<ul>
  <li>John</li>
  <li>Karl</li>
  <li>Brandon</li>
</ul>
<ul>
  <li>Glen</li>
  <li>Tane</li>
  <li>Ralph</li>
</ul>

jQuery 代碼:

$("ul li:first-child")

結果:

[ <li>John</li>, <li>Glen</li> ]

--------------------------------------------------------------------------------

:last-child

匹配最后一個子元素
':last'只匹配一個元素,而此選擇符將為每個父元素匹配一個子元素

Matches the last child of its parent.

返回值

Array<Element>

示例

在每個 ul 中查找最后一個 li

HTML 代碼:

<ul>
  <li>John</li>
  <li>Karl</li>
  <li>Brandon</li>
</ul>
<ul>
  <li>Glen</li>
  <li>Tane</li>
  <li>Ralph</li>
</ul>

jQuery 代碼:

$("ul li:last-child")

結果:

[ <li>Brandon</li>, <li>Ralph</li> ]

--------------------------------------------------------------------------------

:only-child

如果某個元素是父元素中唯一的子元素,那將會被匹配
如果父元素中含有其他元素,那將不會被匹配。

Matches the only child of its parent.

返回值

Array<Element>

示例

在 ul 中查找是唯一子元素的 li

HTML 代碼:

<ul>
  <li>John</li>
  <li>Karl</li>
  <li>Brandon</li>
</ul>
<ul>
  <li>Glen</li>

jQuery 代碼:

$("ul li:only-child")

結果:

[ <li>Glen</li> ]

--------------------------------------------------------------------------------

:input

匹配所有 input, textarea, select 和 button 元素

返回值

Array<Element>

示例

查找所有的input元素

HTML 代碼:

<form>
  <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 代碼:

$(":input")

結果:

[ <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" /> ]

--------------------------------------------------------------------------------

:text

匹配所有的單行文本框

返回值

Array<Element>

示例

查找所有文本框

HTML 代碼:

<form>
  <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 代碼:

$(":text")

結果:

[ <input type="text" /> ]

--------------------------------------------------------------------------------

:password

匹配所有密碼框

返回值

Array<Element>

示例

查找所有密碼框

HTML 代碼:

<form>
  <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 代碼:

$(":password")

結果:

[ <input type="password" /> ]

--------------------------------------------------------------------------------

:radio

匹配所有單選按鈕

返回值

Array<Element>

示例

查找所有單選按鈕

HTML 代碼:

<form>
  <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 代碼:

$(":radio")

結果:

[ <input type="radio" /> ]

--------------------------------------------------------------------------------

:submit

匹配所有提交按鈕

返回值

Array<Element>

示例

查找所有提交按鈕

HTML 代碼:

<form>
  <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 代碼:

$(":submit")

結果:

[ <input type="submit" /> ]


其他的一些 都是一樣的道理:image   ,:reset,:button,:file,:hidden !@#@!%$%
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武陟县| 西峡县| 福鼎市| 清徐县| 大理市| 阿合奇县| 濮阳县| 浏阳市| 岗巴县| 陕西省| 邢台县| 蓬溪县| 嵩明县| 泾川县| 贵阳市| 彭水| 江门市| 陕西省| 新建县| 常山县| 富裕县| 连州市| 广东省| 定日县| 苍溪县| 密云县| 饶河县| 余干县| 泾川县| 芜湖县| 定安县| 土默特右旗| 原阳县| 巴中市| 山丹县| 库伦旗| 鄂州市| 炎陵县| 鹤岗市| 洱源县| 呈贡县|