jQuery datepicker won't work on a AJAX added html element

前端 未结 6 1360
小鲜肉
小鲜肉 2020-12-05 12:06

I have a jQuery datepicker function bound to the \"birthday\" input html element, written in the page header:



        
6条回答
  •  离开以前
    2020-12-05 12:45

    Boris, JK: This was super helpful for me. I have also found that you can use the following for AJAX html if you want to use Datepicker's date range selection:

    $('#groundtransporation').live('focus', function() {
    var gt = $( "#rentalPickUp, #rentalDropOff" ).datepicker({
      defaultDate: "+1w",
      changeMonth: true,
      numberOfMonths: 2,
      onSelect: function( selectedDate ) {
        var option = this.id == "rentalPickUp" ? "minDate" : "maxDate",
          instance = $( this ).data( "datepicker" ),
          date = $.datepicker.parseDate(
            instance.settings.dateFormat ||
            $.datepicker._defaults.dateFormat,
            selectedDate, instance.settings );
        gt.not( this ).datepicker( "option", option, date );
      }
    });
    });
    

提交回复
热议问题