复选框一次选中一个不在gridview中工作



我在gridview 中有多个checkboxes

我想要的是,如果我选择一个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>

请建议如何实现此

您可能需要针对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);
});

使用单选按钮,它们内置了这种行为。

相关内容

最新更新