jQuery selector basic selector

form input: query all input elements under the form, including descendant relationships
form>input: query all input elements under the form, there is a parent-child relationship, but no descendant relationship
form+input: query the first input element at the same level as the form, which is a brother Relationship
form~input: query all input elements at the same level as form, which is a sibling relationship

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325367921&siteId=291194637