Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 当一组文本框中的一个选中时,取消选中该组复选框_Jquery - Fatal编程技术网

Jquery 当一组文本框中的一个选中时,取消选中该组复选框

Jquery 当一组文本框中的一个选中时,取消选中该组复选框,jquery,Jquery,我已经创建了一组动态复选框,我需要的是,当我选中一个复选框时,如果已经选中,则该组其他复选框需要取消选中。我已经创建了一个JS小提琴请检查它 我的代码 $.ajax({ type: "POST", contentType: 'application/json;charset=utf-8', dataType:'json', url : 'getAllRequisitionIds',

我已经创建了一组动态复选框,我需要的是,当我选中一个复选框时,如果已经选中,则该组其他复选框需要取消选中。我已经创建了一个JS小提琴请检查它

我的代码

$.ajax({
              type: "POST",
              contentType: 'application/json;charset=utf-8',
              dataType:'json',
              url : 'getAllRequisitionIds',
              data : JSON.stringify(),
              success : function(data) {
                     // alert("success");
                      if(data!=''){
                        $.each(data, function(i, item) {

 tr = $('<tr/>');
 tr.append($("<td />").html('<input type="checkbox" id="reqid'+i+'" class="reqid" value='+item+'>'));
 tr.append("<td>" + item + "</td>");


                           $('#table_load').append(tr);
                        });


              });
$.ajax({
类型:“POST”,
contentType:'application/json;charset=utf-8',
数据类型:'json',
url:'GetAllRequisitionId',
数据:JSON.stringify(),
成功:功能(数据){
//警惕(“成功”);
如果(数据!=''){
$。每个(数据、功能(i、项){
tr=$('');
tr.append($(“”).html(“”));
tr.append(“+item+”);
$(“#表_加载”).append(tr);
});
});

您可以使用委派的更改事件处理程序来执行此操作

//register a change handler for the checkboxes with class reqid
$('#table_load').on('change', '.reqid', function () {
    if (this.checked) {
        //select all elements with class reqid except current one and uncheck them
        $('.reqid').not(this).prop('checked', false)
    }
})

谢谢重播,我已经更新了我的JSFIDLE,请检查一下