2012-07-10 42 views
1

我可以使用children()和父()但如果输入不是孩子和父母?设置可见的其他选择器没有父母和孩子

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

FIDDLE:http://jsfiddle.net/ykyNq/1/

回答

1

根据您的情况,您可以使用几个不同的选择找到兄弟姐妹。在这种情况下,你可以使用siblings()

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

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

1

您可以使用siblings选择它的所有兄弟姐妹

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

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

(在同一母公司下的同一级别的元素)