use*_*391 0 jquery hidden row onclick show
我有一个表,其中有一行使用display:none隐藏.我想在单击按钮时显示该行.我怎样才能做到这一点??
<table>
<tr>
<td>
<button class="shownextrow">Show Next Row</button>
</td>
</tr>
<tr style="display:none">
<input type="text" name="input"/>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
你可以绑定到按钮并相对找到它,如下所示:
$("button.shownextrow").click(function() {
$(this).closest("tr").next().show();
});
Run Code Online (Sandbox Code Playgroud)
这从按钮变为($(this))了,以<tr>使用.closest(),然后得到.next()兄弟<tr>来.show().您可能想要使用.toggle()而不是,.show()但其余部分是相同的.
你可以在这里尝试一下.请注意,您在示例中<input>直接使用了a <tr>,我将其包装在一个<td>以使其成为有效的演示.