最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2010年11月25日 19:54:19   作者:  
juqery 學習之三 選擇器 子元素與表單,學習jquery的朋友可以參考下。

: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>

參數(shù)

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 !@#@!%$%

相關文章

最新評論

桦南县| 美姑县| 广灵县| 汶川县| 德保县| 土默特右旗| 石柱| 鄂伦春自治旗| 进贤县| 定襄县| 青河县| 冀州市| 白玉县| 大悟县| 信宜市| 花垣县| 金阳县| 永年县| 九龙城区| 南宫市| 辽宁省| 嘉兴市| 堆龙德庆县| 图木舒克市| 遂溪县| 柘城县| 康平县| 兴安县| 邓州市| 东宁县| 博乐市| 宁都县| 汕尾市| 锦州市| 香河县| 津南区| 漯河市| 班戈县| 澄江县| 七台河市| 山阳县|