javascript - 在没有 parent 和 child 的其他选择器上设置可见

标签 javascript jquery html

我可以使用 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() 
})

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

关于javascript - 在没有 parent 和 child 的其他选择器上设置可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11421072/

相关文章:

javascript - Trello 如何处理卡片、列表、 list 等的重新排列

javascript - jQuery 选择器 + 变量目标匹配

javascript - 如何让光标移出输入框?

css - IE float div包装

html - Bootstrap 3 的最佳实践方法

javascript - 从 C# 返回 Json 字符串并使用 javascript 和 jquery 将其显示在文本框中

javascript - 打开新选项卡,然后监听正在触发的事件

javascript - 简化 promise

jquery - 如何使用 Jquery 进行点击和模糊?

javascript - 打开模式时页面滚动到顶部问题