1

children()とparent()を使用できますが、入力がchildrenとparentでない場合はどうなりますか?

<table>
<tr>
<td>
    <input type="checkbox" class="check">
    <select style="display: none"><option>1</option><option>2</option></select>
    <select style="display: none"><option>1</option><option>2</option></select>
    <input type="text" style="display: none">
</td>
    </tr><tr>
    <td>
    <input type="checkbox" class="check">
    <select style="display: none"><option>1</option><option>2</option></select>
    <select style="display: none"><option>1</option><option>2</option></select>
    <input type="text" style="display: none">
</td></tr><tr>
    <td>
    <input type="checkbox" class="check">
    <select style="display: none"><option>1</option><option>2</option></select>
    <select style="display: none"><option>1</option><option>2</option></select>
    <input type="text" style="display: none">
</td></tr><tr>
    <td>
    <input type="checkbox" class="check">
    <select style="display: none"><option>1</option><option>2</option></select>
    <select style="display: none"><option>1</option><option>2</option></select>
    <input type="text" style="display: none">
</td>
</tr>
</table>

クラスチェックでチェックボックスをオンにすると、2を選択して入力が表示されます。jQueryでどのように作成できますか?

フィドル:http : //jsfiddle.net/ykyNq/1/

4

2 に答える 2

1

状況に応じて、いくつかの異なるセレクターを使用して兄弟を見つけることができます。この場合、使用できますsiblings()

$('.check').click(function(){    
    $(this).siblings("select, input").toggle() 
})

http://jsfiddle.net/ykyNq/3/

于 2012-07-10T20:11:06.637 に答える
1

兄弟を使用して、すべての兄弟 (同じ親の下の同じレベルの要素) を選択できます。

$('.check').click(function(){
    $(this).siblings().toggle();
})​

http://jsfiddle.net/ykyNq/4/

于 2012-07-10T20:14:44.350 に答える