无为清净楼资源网 Design By www.qnjia.com
: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. 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" /> ]其他的一些 都是一样的道理:image ,:reset,:button,:file,:hidden !@#@!%$%
标签:
选择器,子元素
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年10月09日
2024年10月09日
- 【原神】V5.0攻略 | 林尼攻略一图流
- 李翊君.1993-相思的烈酒【上华】【WAV+CUE】
- 古巨基.1998-LEO.KU(国)【千禧年代】【WAV+CUE】
- 郭子.2001-原来你什么都不想要创作集丫滚石】【WAV+CUE】
- 《使命召唤:黑色行动6》新预告公布!10月25日发售
- Atlus《暗喻幻想》媒体评分汇总:高分好评如潮!
- 2024金摇杆奖提名揭晓 《黑神话》角逐最佳视觉设计!
- 群星《新说唱2024 第3期 (上)》[320K/MP3][32.76MB]
- 群星《新说唱2024 第3期 (上)》[FLAC/分轨][95.38MB]
- 群星《新说唱2024 第3期 (下)》[320K/MP3][31.36MB]
- 幻兽帕鲁手游什么时候正式上线 最新消息一览
- 西普大陆BOSS位置盘点 解锁天启纪元玩法
- 西普大陆精灵进阶培养攻略 精灵养成指南
- dnf手游法控法系职业哪个强 dnf手游法控法系职业强度排行
- 魔兽世界血藤护目镜图纸在哪买 wlk血藤护目镜图纸购买位置介绍