栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

juqery 学习之三 选择器 子元素与表单

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

juqery 学习之三 选择器 子元素与表单

: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

参数

index (Number) : 要匹配元素的序号,从1开始

示例

在每个 ul 查找第 2 个li

HTML 代码:


     
  • John

  •  
  • Karl

  •  
  • Brandon



     
  • Glen

  •  
  • Tane

  •  
  • Ralph

jQuery 代码:

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

结果:

[
  • Karl
  • ,  
  • Tane
  • ]
    --------------------------------------------------------------------------------
    :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

    示例

    在每个 ul 中查找第一个 li

    HTML 代码:


       
    • John

    •  
    • Karl

    •  
    • Brandon



       
    • Glen

    •  
    • Tane

    •  
    • Ralph

    jQuery 代码:

    $("ul li:first-child")

    结果:

    [
  • John
  • ,
  • Glen
  • ]
    --------------------------------------------------------------------------------
    :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

    示例

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

    HTML 代码:


       
    • John

    •  
    • Karl

    •  
    • Brandon



       
    • Glen

    •  
    • Tane

    •  
    • Ralph

    jQuery 代码:

    $("ul li:last-child")

    结果:

    [
  • Brandon
  • ,
  • Ralph
  • ]
    --------------------------------------------------------------------------------
    :only-child 如果某个元素是父元素中唯一的子元素,那将会被匹配 如果父元素中含有其他元素,那将不会被匹配。
    Matches the only child of its parent. If the parent has other child elements, nothing is matched. 返回值

    Array

    示例

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

    HTML 代码:


       
    • John

    •  
    • Karl

    •  
    • Brandon



       
    • Glen
    • jQuery 代码:

      $("ul li:only-child")

      结果:

      [
    • Glen
    • ]
      --------------------------------------------------------------------------------
      :input 匹配所有 input, textarea, select 和 button 元素
      Matches all input, textarea, select and button elements. 返回值

      Array

      示例

      查找所有的input元素

      HTML 代码:

      jQuery 代码:

      $(":input")

      结果:

      [ , , , , , , , , ]
      --------------------------------------------------------------------------------
      :text 匹配所有的单行文本框
      Matches all input elements of type text. 返回值

      Array

      示例

      查找所有文本框

      HTML 代码:

      jQuery 代码:

      $(":text")

      结果:

      [ ]
      --------------------------------------------------------------------------------
      :password 匹配所有密码框
      Matches all input elements of type password. 返回值

      Array

      示例

      查找所有密码框

      HTML 代码:

      jQuery 代码:

      $(":password")

      结果:

      [ ]
      --------------------------------------------------------------------------------
      :radio 匹配所有单选按钮
      Matches all input elements of type radio. 返回值

      Array

      示例

      查找所有单选按钮

      HTML 代码:

      jQuery 代码:

      $(":radio")

      结果:

      [ ]
      --------------------------------------------------------------------------------
      :submit 匹配所有提交按钮
      Matches all input elements of type submit. 返回值

      Array

      示例

      查找所有提交按钮

      HTML 代码:

      jQuery 代码:

      $(":submit")

      结果:

      [ ]

      其他的一些 都是一样的道理:image   ,:reset,:button,:file,:hidden !@#@!%$%
    转载请注明:文章转载自 www.mshxw.com
    本文地址:https://www.mshxw.com/it/114983.html
    我们一直用心在做
    关于我们 文章归档 网站地图 联系我们

    版权所有 (c)2021-2022 MSHXW.COM

    ICP备案号:晋ICP备2021003244-6号