为了账号安全,请及时绑定邮箱和手机立即绑定

使用 Javascript 在 asp.net 中的每一行中仅允许在 Gridview 中选择一个

使用 Javascript 在 asp.net 中的每一行中仅允许在 Gridview 中选择一个

Smart猫小萌 2023-05-25 17:15:38
我想使用 JavaScript 从网格视图的每一行中只选择一个单选按钮。我在 Gridview 的每一行中使用了 4 个单选按钮。我试过了...<script>            function GetCheckedRows() {                var radio1 = null;                var radio2 = null;                var radio3 = null;                var radio4 = null;                $("#GridView1 tr").each(function () {                    radio1 = $(this).find(".RadioButton1");                    if (radio1.is(':checked')) {                        radio2.checked = false;                        radio3.checked = false;                        radio4.checked = false;                    }                });            }        </script>]
查看完整描述

2 回答

?
MYYA

TA贡献1868条经验 获得超4个赞

给每行单选按钮一个不同的名字


<div class="row">

  <input type="radio" name="rowA" /> Label A

  <input type="radio" name="rowA" /> Label B

  <input type="radio" name="rowA" /> Label C

  <input type="radio" name="rowA" /> Label D     

</div>

<div class="row">

  <input type="radio" name="rowB" /> Label A

  <input type="radio" name="rowB" /> Label B

  <input type="radio" name="rowB" /> Label C

  <input type="radio" name="rowB" /> Label D     

</div>


查看完整回答
反对 回复 2023-05-25
?
jeck猫

TA贡献1909条经验 获得超7个赞

javascript代码


<script src="https://code.jquery.com/jquery-2.2.4.js"></script>


$(document).on('click','.radio-class',function(){

  $this = $(this);

  // uncheck all other radio inputs except this one

  $('.radio-class').not($this).prop('checked', false);

});

单选按钮


<asp:RadioButton ID="RadioButton1" GroupName="radio-class" runat="server" />


查看完整回答
反对 回复 2023-05-25
  • 2 回答
  • 0 关注
  • 78 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信