【发布时间】:2017-06-18 14:15:50
【问题描述】:
我有一个复选框,onclick 显示一个按钮,但是一次只能单击一个复选框;当我单击复选框时,它会显示所有行的按钮。并且当我单击一个复选框并且同时如果我选中下一个复选框时,它会继续显示按钮(对于选中的最后一个复选框),即使它现在没有选中。对不起,如果我不清楚,请查看下面的测试代码以获取更多信息.选中的复选框只应出现一个按钮,如果未选中的按钮不应出现。任何帮助将不胜感激。
$(document).on('click', ".your", function() {
$('.your').not(this).prop('checked', false); //this will make only on checkbox to be checked
$('.deleteButton').toggle(this.checked);
});
.testtable{
border:1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="testtable">
</th>
<tr>testcolumn</tr>
</th>
<tr><td>
<input type="checkbox" class="your" value="yourCheckBoxVal">
<input type="button" class="deleteButton" style="display:none">
</td></tr>
<tr><td>
<input type="checkbox" class="your" value="yourCheckBoxVal">
<input type="button" class="deleteButton" style="display:none">
</td></tr>
</td></tr>
<tr><td>
<input type="checkbox" class="your" value="yourCheckBoxVal">
<input type="button" class="deleteButton" style="display:none">
</td></tr>
</table>
【问题讨论】:
标签: javascript jquery