6

我一生都无法弄清楚为什么这段代码不起作用。我确定我在做一些非常愚蠢的事情,但我就是找不到!我目前只是试图禁用所有日期栏“7-8-2013”​​。对此的任何帮助将不胜感激。谢谢!

<!doctype html>


<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>Calender Control Test</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>

var enableDays = ["7-8-2013"];


 $(function enableAllTheseDays(date) {
    var m = date.getMonth(), var d = date.getDate(), var y = date.getFullYear();
    for (i = 0; i < enableDays.length; i++) {
        if($.inArray((d+1) + '-' + m + '-' + y,enableDays) != -1) {
            return [true];
            }
        }
        return [false];


    $('#datepicker').datepicker({dateFormat: 'dd-mm-yy', beforeShowDay: enableAllTheseDays});

  </script>
</head>
<body>



<div id="datepicker"></div>


</body>
</html>
4

2 回答 2

19

尝试

jQuery(function(){

    var enableDays = ["7-8-2013"];

    function enableAllTheseDays(date) {
        var sdate = $.datepicker.formatDate( 'd-m-yy', date)
        if($.inArray(sdate, enableDays) != -1) {
            return [true];
        }
        return [false];
    }

    $('#datepicker').datepicker({dateFormat: 'dd-mm-yy', beforeShowDay: enableAllTheseDays});
})

演示:小提琴

于 2013-08-02T07:31:34.260 回答
2

试试这个

$(document).ready(){

    var enableDays = ["7-8-2013"];
    function enableAllTheseDays(date) {
            var sdate = $.datepicker.formatDate( 'd-m-yy', date)
            if($.inArray(sdate, enableDays) != -1) {
                return [true];
            }
            return [false];
        }

        $('#datepicker').datepicker({dateFormat: 'dd-mm-yy', beforeShowDay: enableAllTheseDays});
    })

希望它会有所帮助

于 2013-08-02T07:34:48.213 回答