禁用具有不同日期的复选框

Disable checkbox having different date

本文关键字:日期 复选框      更新时间:2023-09-26
  <?php 
    while($row = mysqli_fetch_array($result)){
  ?>
    <tr>
      <td>
          <input type="checkbox" 
                 id="<?php echo $row['invoice_id']; ?>" 
                 name="invoice_id[]" 
                 rel="<?php echo $row['due_date']; ?>" 
                 value="<?php echo $row['invoice_id'];?>">
       </td>
       <td><?php echo $row['invoice_no']; ?></td>
       <td><?php echo $row['due_date']; ?></td>
    </tr>
    <?php
    }
    ?>

我的问题是如何禁用所有不等于选中第一个复选框的截止日期的复选框

invoice_no              due_date
1                       10-15-2014
2                       10-15-2014
3                       10-16-2014
4                       10-17-2014

如果我选中invoice_no 1,invoice_no 3 和 4 将被禁用如果我取消选中invoice_no 1,则将启用所有check_box

到目前为止,我

只有这个,不知道下一步该做什么,我搜索了网络,但仍然找不到如何做到这一点

$("input[type=checkbox]").change(function() {
    $due_date = $(this).attr("rel"); 
});

TIA为您提供帮助.....

你可以试试这个:

<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
$(document).ready(function() {
    $('input[type=checkbox]').change(function(){
        var chk = $(this).attr('rel');
        if($(this).is(':checked'))
        {
            $('input[type=checkbox]').each(function(){
                        var chks = $(this).attr('rel');
                        if(chk != chks)
                        {
                           $(this).attr('disabled','true'); 
                        }
                });
         }
        else
        {
            var temp ='';
            $('input[type=checkbox]').each(function(){                    
                    if($(this).is(':checked'))
                    {
                        temp = $(this).attr('rel');                               
                        return false;                                
                    }                       
            });
            $('input[type=checkbox]').each(function(){                    
                    if(temp != chk)
                    {
                        $(this).removeAttr('disabled');                            
                    }                       
            });
        }
});
</script>

查看此代码。

$(document).ready(function(){
$("input[type=checkbox]").change(function() {
	//alert($(this).attr("rel"));
	$due_date = $(this).attr("rel");
	$id = $(this).val();
    
    var $check = false;
    
	if($(this).is(':checked')){
		$("input[type=checkbox]").each(function(){
			if($(this).val()!=$id){
				if($(this).attr("rel")==$due_date){
					$(this).prop('disabled',false);
				}else{
					$(this).prop('disabled',true);
				}
			}
		});
	}else{
		$("input[type=checkbox]").each(function(){
            if($(this).val()!=$id & $(this).is(':checked')){
                $check = true;
            }
		});
        if(!$check){    
            $("input[type=checkbox]").each(function(){
               $(this).prop('disabled',false);
            });
        }
	}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" 
                 id="1" 
                 name="invoice_id[]" 
                 rel="10-15-2014" 
                 value="1">
		<input type="checkbox" 
                 id="2" 
                 name="invoice_id[]" 
                 rel="10-15-2014" 
                 value="2">
		<input type="checkbox" 
                 id="3" 
                 name="invoice_id[]" 
                 rel="10-16-2014" 
                 value="3">
		<input type="checkbox" 
                 id="4" 
                 name="invoice_id[]" 
                 rel="10-17-2014" 
                 value="4">

这将起作用.. :)