Bootstrap Datepicker如何获取年份和月份 [英] How to get year and month of Bootstrap Datepicker as it on change
问题描述
我是这个datepicker的新人,我不知道如何获取变更事件的月和年字符串 changeMonth
和 changeYear
。
这是一个指向该插件的链接: https://github.com/eternicode/bootstrap-datepicker
I'm new to this datepicker and I don't know how to get the month and year string on change events changeMonth
and changeYear
.
Here is a link to the plugin: https://github.com/eternicode/bootstrap-datepicker
问题是onchange仅捕获从几个月到几年的转换。我只能获取所选日期的日期/日期,在转换期间没有选择任何内容。
The issue is that onchange captures only the transition from months to years. I am only able to get the day/date of the selected date, and nothing is selected during transition.
我试图从div获取文字,但我总是选择太晚。如何获取转换后选择的值的月份和年份。
I tried to grab text from the div, but I am always one selection too late. How can I get the month and year of the value that is selected after a transition.
澄清:
getYear()当我们看到从十年视图改变后的所有12个月
To clarify: getYear() when we see all 12 months after changing from the decade view
getMonth()当我们看到月视图后的天数
getMonth() when we see days after the month view
我的小提琴: http://jsfiddle.net/vj3cdzbc/2/
推荐答案
获取月份:
$("#datepicker").datepicker().on('changeMonth', function(e){
var currMonth = new Date(e.date).getMonth() + 1;
});
获取年份
$("#datepicker").datepicker().on('changeYear', function(e){
var currYear = String(e.date).split(" ")[3];
});
这篇关于Bootstrap Datepicker如何获取年份和月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!