How to get the date from jQuery UI datepicker

前端 未结 6 1076
渐次进展
渐次进展 2020-11-30 01:44

I want to get the date from datepicker whenever user choose the date in jQuery UI datepicker and click the button on the form.

well I need to get the day, month and

6条回答
  •  暖寄归人
    2020-11-30 01:59

    You can retrieve the date by using the getDate function:

    $("#datepicker").datepicker( 'getDate' );
    

    The value is returned as a JavaScript Date object.

    If you want to use this value when the user selects a date, you can use the onSelect event:

    $("#datepicker").datepicker({
       onSelect: function(dateText, inst) { 
          var dateAsString = dateText; //the first parameter of this function
          var dateAsObject = $(this).datepicker( 'getDate' ); //the getDate method
       }
    });
    

    The first parameter is in this case the selected Date as String. Use parseDate to convert it to a JS Date Object.

    See http://docs.jquery.com/UI/Datepicker for the full jQuery UI DatePicker reference.

提交回复
热议问题