2015-11-17 49 views

回答

8

您可以使用下面的技術做上述的事情。如果你需要相反的情況,那麼只需翻轉禁用的標誌,然後完成。下面的代碼可以直接在您的應用程序中使用。

$(function() { 
 
     $("#datepicker").datepicker({ 
 
     defaultDate: new Date(), 
 
      beforeShowDay: function(date) { 
 
       var disabled = true, // enabled default day 
 
       // total days of current month 
 
       numOfDays = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate(); 
 
        if (numOfDays % 2 == 0) { 
 
         disabled = (date.getDate() % 2 == 0) //so for even days months, disable the odd days 
 
        } else { 
 
         disabled = (date.getDate() % 2 != 0) //so for odd days months, disable the even days 
 
        } 
 
        return [disabled, ""] 
 
      } 
 
     }); 
 
    }); 
 
<link href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" rel="stylesheet" /> 
 
<p>Date: 
 
    <input type="text" id="datepicker" /> 
 
</p> 
 

 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>

+0

非常感謝:d –

相關問題