2010-07-30 51 views
0

我們在表格標題頂部有一個天數列表,如果所選日期大於當天(例如今天是30日,但選擇31日),我們希望禁用全部檢查功能。我們將允許checkAll在小於當前日期的任何日期工作。我們如何實現這一目標?如何防止未來日期的checkAll選擇?

<script type="text/javascript"> 
     jQuery(document).ready(function(){ 
      // This provides selectAll, clearAll capability 
      jQuery('#records').find('thead th').click(function(){ 
       var ch = jQuery(this).find("input[type='checkbox']").attr('checked'); 
       var col = jQuery(this).prevAll().length; 
       var ch = jQuery(this).find("input[type='checkbox']").attr('checked'); 
       jQuery('#records').find('tbody td').each(function(){ 
        var tdId = jQuery(this).attr('id'); 
        if(col == tdId) { 
         if(jQuery(this).hasClass('user-present')) { 
          // Toggle the value of attribute checked for the checkbox 
          jQuery(this).find("input[type='checkbox']").attr('checked', true); 
         } 
        } 
       }); 
      }); 

     }); 
    </script> 

回答

1

1)你可以標記與服務器端的一個CSS類中的每個「未來」的日期,然後只寫一個適當的CSS選擇器來過濾他們。

2)您可以將title屬性與日期字符串(例如2010-07-30)附加到每個元素,並進一步比較兩個日期。

var today = new Date(); 
var check_me = new Date("2012-12-21"); // element.attr("title") instead of "2012-12-21" in your case 
if (check_me <= today) 
{ 
    //Everything is ok 
} 
相關問題