我可以使用 children() 和 parent() 但如果输入不是 child 和 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 制作?
fiddle : http://jsfiddle.net/ykyNq/1/
最佳答案
根据您的情况,您可以使用一些不同的选择器来查找 sibling 。在这种情况下,您可以使用 siblings()
$('.check').click(function(){
$(this).siblings("select, input").toggle()
})
关于javascript - 在没有 parent 和 child 的其他选择器上设置可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11421072/