Javascript 在没有父项和子项的其他选择器上设置可见
我可以使用children()和parent(),但如果输入不是children和parent呢Javascript 在没有父项和子项的其他选择器上设置可见,javascript,jquery,html,Javascript,Jquery,Html,我可以使用children()和parent(),但如果输入不是children和parent呢 <table> <tr> <td> <input type="checkbox" class="check"> <select style="display: none"><option>1</option><option>2</option></select>
<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>
12
12
12
12
12
12
12
12
如果我用类check选中复选框,那么2 select和input应该是可见的。我如何使用jQuery进行查询
小提琴:根据您的情况,您可以使用几个不同的选择器来查找兄弟姐妹。在这种情况下,您可以使用
兄弟姐妹()
您可以使用来选择它的所有同级(同一父级下同一级别的元素)
$('.check').click(function(){
$(this).siblings("select, input").toggle()
})
$('.check').click(function(){
$(this).siblings().toggle();
})