Domanda

what I need is, when pressed the blank, display only June calendarie and either highlight from 2014-06-01 to 2014-06-07 or disable the rest of dates. I have seen posts about hightlighting and tried things without success. I will be glad if someone could help me and get this ready for once, thank you in advance, here is what I have:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>
      jQuery UI Datepicker - Opciones de localización
    </title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
    <script src="jquery.ui.datepicker-es.js"></script>

    <script>
      $(function () {
        $("#datepicker").click(function(){
          $.datepicker.setDefaults($.datepicker.regional["es"]);
          $("#datepicker").datepicker({
            dateFormat: 'yy-mm-dd',
            firstDay: 1
          });
        });
      });
    </script>
  </head>

  <body>
    <input id="datepicker" type="text">
  </body>
</html>
È stato utile?

Soluzione

The datepicker widget has a min and max date attribute.

<script>
      $(function () {
        $("#datepicker").click(function(){
          $.datepicker.setDefaults($.datepicker.regional["es"]);
          $("#datepicker").datepicker({
            dateFormat: 'yy-mm-dd',
            firstDay: 1,
            minDate: new Date( *enter your start date here* ),
            maxDate: new Date( *enter your end date here* )
          });
        });
      });
    </script>

Documentation: http://api.jqueryui.com/datepicker/

Altri suggerimenti

This code may help you to enable specific dates only.

var availableDates = ["1-6-2014","2-6-2014","3-6-2014","4-6-2014","5-6-2014","6-6-2014","7-6-2014",];

function available(date) 
{
    dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();

    if ($.inArray(dmy, availableDates) != -1) 
    {
        return [true, "","Available"];
    }
    else 
    {
        return [false,"","unAvailable"];
    }
}

$('#date').datepicker({ beforeShowDay: available });

Hope it helps..!!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top