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

首頁 > 開發 > 綜合 > 正文

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

2024-07-21 02:04:41
字體:
來源:轉載
供稿:網友

匹配其父元素下的第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.
While ':eq(index)' matches only a single element, this matches more then one: One for each parent. The specified index is one-indexed, in contrast to :eq() which starst at zero.
返回值
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.
While ':first' matches only a single element, this matches more then one: One for each 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.
While ':last' matches only a single element, this matches more then one: One for each 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.
If the parent has other child elements, nothing is matched.
返回值
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 元素

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

Matches all input, textarea, select and button elements.
返回值
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匹配所有的單行文本框

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

Matches all input elements of type 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匹配所有密碼框

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

Matches all input elements of type 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匹配所有單選按鈕

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

Matches all input elements of type 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匹配所有提交按鈕

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

Matches all input elements of type 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" /> ]

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 靖江市| 浮梁县| 义马市| 晋宁县| 长兴县| 长白| 陇川县| 宣恩县| 九台市| 赤水市| 敦化市| 鄂托克前旗| 灵山县| 清河县| 大石桥市| 江津市| 石阡县| 东台市| 泰来县| 长泰县| 团风县| 建阳市| 自贡市| 石嘴山市| 兰考县| 寻甸| 五常市| 灵璧县| 濮阳县| 灌阳县| 芒康县| 谢通门县| 香格里拉县| 永安市| 南安市| 民勤县| 漯河市| 东明县| 云龙县| 威宁| 望都县|