dongwenxiu5200 2014-10-10 05:34
浏览 106
已采纳

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

  <?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
    }
    ?>

my question is how to disable all check box which is not equal to due date of the first check box checked

example

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

if i checked invoice_no 1, invoice_no 3 and 4 will be disabled and if i unchecked invoice_no 1, all check_box will be enabled

as of now i only have this and don't know whats next thing to do, i search the web but still i cant find how to do this

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

TIA for your help.....

  • 写回答

2条回答 默认 最新

  • douguabu8960 2014-10-10 06:09
    关注

    Check out this code..

    $(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">

    This will work.. :)

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料