1

如何在 jQuery ui 中获取数据选择器的数据?我有下一个代码,但只获得默认值。(我只用几年)

$('#datePickerTempe').datepicker( {
    changeMonth: false,
    changeYear: false,
    dateFormat: 'MM yy',
    //To hide months:
    stepMonths: 12,  
    monthNames: ["","","","","","","","","","","",""], 
    //Range
    minDate: '-4y',  //'M'-> month | 'w'-> week | 'd'-> day
    maxDate: '0y',

    buttonImageOnly: true 
});

$('#datePickerTempe').on('click', function(){ 
console.log('año: '+$('#datePickerTempe').val()); });
4

3 回答 3

1

从 datepicker 获取当前日期(如果没有选择,则为 null):

var selectedDate = $('#datePickerTempe').datepicker("getDate");

您还可以将onSelect处理程序添加到datepicker

$('#datePickerTempe').datepicker( {
    onSelect: function (dateText, inst) {
        console.log(dateText);
    }
});

参考datepicker getDate方法和datepicker onSelect选项

于 2013-01-26T11:18:33.767 回答
0
<input type="text" id="date" name="date" value=""/>    

<script>
    var date_fields = $('#date');
    date_fields.datepicker({
        format: 'mm/dd/yyyy'
    }).on('changeDate', function(ev){
        date_fields.datepicker('hide');
        date_fields.blur();
    });
</script>

添加的脚本http://www.eyecon.ro/bootstrap-datepicker/

于 2013-01-26T11:23:17.053 回答
0
$("#datepicker").change(function() {
    alert($(this).val());
});

在这里工作得很好。

于 2013-01-26T11:23:43.793 回答