使用选择器使用jquery隐藏元素

Tal*_*les -2 jquery hide jquery-selectors

1个问题1.说我有这个:

<body>
    <form>
        <h3>blah</h3>
        <table>
            <tr>
                <th>Input 1:</th>
                <td><input type="text" id="some-input-a" name="some-input-a" /></td>
            </tr>
            <tr>
                <th>Input 2:</th>
                <td><input type="text" id="other-input" name="other-input" /></td>
            </tr>
        </table>
        <h3>blah</h3>
        <table>
            <tr>
                <th>Input 3:</th>
                <td>
                    <select name="my-select" id="my-select">
                        <option value="1">My 1</option>
                        <option value="c">Your f</option>
                        <option value="m">This g</option>
                    </select>
                </td>
            </tr>
            <tr>
                <th>Input 4:</th>
                <td><input type="password" id="pass-input" name="next-input" /></td>
            </tr>
            <tr>
                <th>Input 5:</th>
                <td><input type="password" id="pass-confirm" name="pass-confirm" /></td>
            </tr>
        </table>
        <h3>blah</h3>
        <table>
            <tr>
                <th>Input 6:</th>
                <td><input type="text" id="next-one" name="next-one" /></td>
            </tr>
            <tr>
                <th>Input 7:</th>
                <td><input type="text" id="more-inputs" name="more-inputs" /></td>
            </tr>
            <tr>
                <th>Input 8:</th>
                <td><input type="text" id="form-input" name="form-input" /></td>
            </tr>
            <tr>
                <th>Input 9:</th>
                <td><textarea name="description" id="description" rows="5" cols="30"></textarea></td>
            </tr>
            <tr>
                <th>Input 10:</th>
                <td><input type="text" id="input-10" name="input-10" /></td>
            </tr>
        </table>
    </form>
</body>
Run Code Online (Sandbox Code Playgroud)

有一种简单的隐藏方式:

  1. 完全是第三张桌子
  2. Textarea所在的行
  3. 具有ID的元素的行是"描述"
  4. 第3个表的第2行
  5. 第三个 <h3>
  6. 第五个输入标签

使用选择器

the*_*dox 5

1.

$('form table:eq(2)').hide();
Run Code Online (Sandbox Code Playgroud)

2.

$('form table tr').has('textarea').hide();
Run Code Online (Sandbox Code Playgroud)

3.

$('#description').hide();
Run Code Online (Sandbox Code Playgroud)

4.

$('form table:eq(2) tr:eq(1)').hide();
Run Code Online (Sandbox Code Playgroud)

5.

$('form h3:eq(2)').hide();
Run Code Online (Sandbox Code Playgroud)

6.

$('form input:eq(4)').parent().prev('td').hide();
Run Code Online (Sandbox Code Playgroud)

阅读有关jQuery选择器的信息.