我在checkboxes
gridview
我想要的是,如果我选择一个checkbox
并选择另一个,则第一个复选框应取消选中,第二个复选框应该被选中。
我试过下面的代码
$('.chk').on('change', function () {
alert('click');
$('span.input.chk').not(this).prop('checked', false);
});
我的浏览器呈现的HTML复选框位于
之下 <span class="chk" title="136"><input id="ContentPlaceHolder1_GrdInvoiceDetailsSearch_ob_GrdInvoiceDetailsSearchBodyContainer_ctl02_0_ctl00_0_ChkID_0" type="checkbox" name="ctl00$ContentPlaceHolder1$GrdInvoiceDetailsSearch$ob_GrdInvoiceDetailsSearchBodyContainer$ctl02$ctl02$ctl00$ChkID" /></span>
</div><div class="ob_gCd">136</div></div></td><td class="ob_gCW" style="width:25%;"><div class="ob_gCc1"><div class="ob_gCc2">GANDHI ADHIVITIYA COMBINE</div></div></td><td class="ob_gCW" style="width:25%;"><div class="ob_gCc1"><div class="ob_gCc2R">292700</div></div></td><td class="ob_gCW" style="width:25%;"><div class="ob_gCc1"><div class="ob_gCc2R">180</div></div></td><td class="ob_gCW ob_gC_Lc" style="width:21%;"><div class="ob_gCc1"><div class="ob_gCc2R">120</div></div></td></tr><tr class="ob_gRA"><td class="ob_gC ob_gC_Fc" style="width:4%;"><div class="ob_gCc1"><div class="ob_gCc2">
<span class="chk" title="102"><input id="ContentPlaceHolder1_GrdInvoiceDetailsSearch_ob_GrdInvoiceDetailsSearchBodyContainer_ctl02_1_ctl00_1_ChkID_1" type="checkbox" name="ctl00$ContentPlaceHolder1$GrdInvoiceDetailsSearch$ob_GrdInvoiceDetailsSearchBodyContainer$ctl03$ctl02$ctl00$ChkID" /></span>
请建议如何实现这个目标
答案 0 :(得分:1)
您可能需要根据标记定位chk
课程下方的实际复选框元素,目前您定位的是父<span>
元素:
// When one of your checkboxes is checked
$('.chk :checkbox').on('change', function () {
// Uncheck all of them that are not this
$('.chk :checkbox').not(this).prop('checked', false);
});
答案 1 :(得分:0)
使用单选按钮,它们内置了此行为。