jQuery: enabling/disabling datepicker

前端 未结 18 1099
青春惊慌失措
青春惊慌失措 2020-12-03 06:38

In my php-file, I want to use the jQuery Datepicker.

When my file loads, I create the Datepicker disabled.

Then, when a special field in my php-file (it is a

18条回答
  •  感动是毒
    2020-12-03 07:10

    You can use this code to toggle disabled with jQuery Datepicker and with any other form element also.

    /***
      *This is the toggle disabled function Start
      *
      **/
    (function($) {
      $.fn.toggleDisabled = function() {
        return this.each(function() {
          this.disabled = !this.disabled;
          if ($(this).datepicker("option", "disabled")) {
            $(this).datepicker("option", "disabled", false);
          } else {
            $(this).datepicker("option", "disabled", true);
          }
    
        });
      };
    })(jQuery);
    
    /***
      *This is the toggle disabled function Start
      *Below is the implementation of the same
      **/
    
    $(".filtertype").click(function() {
      $(".filtertypeinput").toggleDisabled();
    });
    
    /***
      *Implementation end
      *
      **/
    
    $("#from").datepicker({
      showOn: "button",
      buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif",
      buttonImageOnly: true,
      buttonText: "Select date",
      defaultDate: "+1w",
      changeMonth: true,
      changeYear: true,
      numberOfMonths: 1,
      onClose: function(selectedDate) {
        $("#to").datepicker("option", "minDate", selectedDate);
      }
    });
    $("#to").datepicker({
      showOn: "button",
      buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif ",
      buttonImageOnly: true,
      buttonText: "Select date",
      defaultDate: "+1w",
      changeMonth: true,
      changeYear: true,
      numberOfMonths: 1,
      onClose: function(selectedDate) {
        $("#from").datepicker("option", "maxDate", selectedDate);
      }
    });
    
    
    
    
    
    By Date
    By Year
    Report

提交回复
热议问题