何时检查复选框其他复选框同一行取消选中

时间:2013-02-18 18:35:39

标签: asp.net html checkbox

我必须列出支票

 <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未选中时,我不知道工作

1 个答案:

答案 0 :(得分: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);
    }
});
相关问题