jQuery DatePicker: Get Selected Date

跟風遠走 提交于 2019-12-10 14:29:14

问题


I need to be able to grab the selected date from the Datepicker and populate another textbox with the selected value. I am currently using the onClose function like this:

$('#defaultDate').datepicker({
    onClose:function(theDate) {
        $('#txtEntry1').text = theDate;
    }
});

回答1:


There's an easier way to do it. Use the built-in alt-field option and you're done.

Populate an alternate field with its own date format whenever a date is selected using the altField and altFormat options. This feature could be used to present a human-friendly date for user selection, while passing a more computer-friendly date through for further processing.




回答2:


Have you looked through the docs? http://docs.jquery.com/UI/Datepicker#events

onSelect function(dateText, inst)

Allows you to define your own event when the datepicker is selected. The function receives the selected date as text and the datepicker instance as parameters. this refers to the associated input field. Code examples

Supply a callback function to handle the onSelect event as an init option.

$('.selector').datepicker({
   onSelect: function(dateText, inst) { ... }
});


来源:https://stackoverflow.com/questions/2311608/jquery-datepicker-get-selected-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!