【问题标题】:when to check a checkbox other checkbox same row uncheck何时选中复选框 其他复选框 同一行 取消选中
【发布时间】:2013-02-19 02:50:13
【问题描述】:

我必须列出检查

 <input type="checkbox" value="18" name="yes" id="yes1">
 <input type="checkbox" value="13" name="yes" id="yes2">
 <input type="checkbox" value="12" name="yes" id="yes3">

和其他列表复选框

<input type="checkbox" value="14" name="no" id="no2">
<input type="checkbox" value="18" name="no" id="no2">
<input type="checkbox" value="12" name="yo" id="no2">

但是当我选中复选框 id yes1 时我不知道要工作,id no1 没有选中

【问题讨论】:

  • 你的意思是给你的“不”inputs 相同的id?那是无效的 HTML。
  • 您可能想看看MutuallyExclusiveCheckBox 的 ASP.Net Ajax ToolKit。在演示中,它取消选中它旁边的复选框。

标签: asp.net html checkbox


【解决方案1】:

假设您将复选框更改为 name="no",因为您有重复的 ID,并且带有 name="yo" 的复选框是错误的,如下所示:

<input type="checkbox" value="18" name="yes" id="yes1">
<input type="checkbox" value="13" name="yes" id="yes2">
<input type="checkbox" value="12" name="yes" id="yes3">

<input type="checkbox" value="14" name="no" id="no1">
<input type="checkbox" value="18" name="no" id="no2">
<input type="checkbox" value="12" name="yo" id="no3">

你可以用 jQuery 做到这一点:

$("input[name=yes]").click(function() {
    var current = this.id.replace("yes","");
    if($(this).is(':checked')) {
        $("#no" + current).prop('checked', false);
    }
});

$("input[name=no]").click(function() {
    var current = this.id.replace("no","");
    if($(this).is(':checked')) {
        $("#yes" + current).prop('checked', false);
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 2013-06-24
    • 2019-09-09
    • 1970-01-01
    • 2013-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多