复选框基于签入jquery禁用

时间:2014-09-23 05:32:37

标签: javascript jquery checkbox

嗨我在复选框值上有两个条件,所以检查

i)if user click "no record " other checkbox had to disable  or
ii)it have to alert only no record have to select like that or
iii) while click of no record other selection have not allowed to check

我的代码:

<tr class='tablecolor-L-TD' id="+sno+">" +
              "<td class='lc_sno_1' ><center> "+sno+"</center></td>"+
              "<td class='lc_survey_1' ><center> "+v.surveyNo+"</center></td>" +
              "<td class='lc_subdiv_1' ><center> "+v.subdivNo+"</center></td>" +
              "<td class='lc_ExtAres_1' ><center> "+v.ext_ares+"</center></td>" +
              "<td class='lc_ownerdetail_1' ><center> "+cnt_OwnrName+"</center></td>"+val+"" +
              "<div id='td_select' style='display: block'>" +
              "<td class='selectall'><center>" +
              "<input type = 'checkbox'  class='chkNumber' value='"+JSON.stringify(v)+"' id = check"+sno+" " +
              " name=check"+sno+" onClick='addSave(this); ;' /></center></td>"

例如:

<input id="check1" class="chkNumber" type="checkbox" onclick="addSave(this); ;" name="check1" value="{"patta":275,"authorityno":1,"villageCode":"057","ownersChitta":}"

<input id="check2" class="chkNumber" type="checkbox" onclick="addSave(this); ;" name="check2" value="{ "flag": "No records"}"

新手如何检查???

2 个答案:

答案 0 :(得分:1)

试试这个:将更改事件绑定到“无记录”&#39;复选框和禁用其他复选框(如果选中)或未选中时启用。使用 .prop() 来禁用/启用复选框

$(function(){
  $('#check2').change(function(){
    $('.chkNumber').not(this).prop('disabled',this.checked);
  });
});

编辑 - 正如OP所说,id每次都不会相同,但是没有记录的价值&#39;复选框将是相同的。以下是我更新的解决方案

$(function(){
      $('.chkNumber').change(function(){
        var value = $(this).val();
        if(value == '{ "flag": "No records"}')
          $('.chkNumber').not(this).prop('disabled',this.checked);
      });
 });

答案 1 :(得分:0)

试试这个

&#13;
&#13;
$(".chkNumber").change(function() {
  var self = this;
  $(".chkNumber").prop('disabled', true);
  $(this).removeAttr('disabled');
});
&#13;
&#13;
&#13;