首页 > Web开发 > 详细

jQuery选择器基本选择器

时间:2018-05-06 11:04:59      阅读:188      评论:0      收藏:0      [点我收藏+]
form input:查询form下所有input元素,含有后代关系
form>input:查询form下所有input元素,有有父子关系,没有后代关系
form+input:查询与form同级的第一个input元素,是兄弟关系
form~input:查询与form同级的所有input元素,是兄弟关系

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="../js/jquery-1.6.js"></script>
  </head>
  <body>
    <form>
        <input type="text" value="a"/>      
        <table>
            <tr>
                <td>
                    <input type="checkbox" value="b"/>
                </td>
            </tr>           
        </table>
    </form>
    <input type="radio" value="c"/>
    <input type="radio" value="d"/>
    <input type="radio" value="e"/>
    <script type="text/javascript">

        //1)找到表单form下所有的input元素的个数
        //alert($("form input").size());

        //2)找到表单form下所有的子级input元素个数
        //alert($("form>input").size());

        //3)找到表单form同级第一个input元素的value属性值
        //alert($("form+input").val());

        //4)找到所有与表单form同级的input元素个数
        alert($("form~input").size());

    </script>
  </body>
</html>

jQuery选择器基本选择器

原文:http://blog.51cto.com/357712148/2113186

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!