如何获得选定的年份在datepicker? [英] how to get the selected year in datepicker?
本文介绍了如何获得选定的年份在datepicker?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用datepicker作为我的输入名称 birth_day
。我想计算当年和选定年份的年龄。
I am using datepicker for my input name birth_day
. And I want to calculate the age from the current year and selected year.
current_yr - selected_yr
但我不知道如何从日期选择器中获取所选年份。
but I have no idea on how can I get the selected year from date picker.
这是我的代码看起来像。
this is my code look like.
<script>
function dateYear(){
var d = new Date();
var year = d.getFullYear();
return year;
}
$(function() {
$( "#id_birth_date" ).datepicker({ dateFormat: 'yy-mm-dd' });
//how can I get the selected year?
});
</script>
<input type="text" name="birth_day" id="bd">
<input type="text" name="age" id="ag">
有没有人可以给我一个关于我的情况的想法?
does anyone can give me an idea about my case?
任何帮助将不胜感激...
any help will be appreciated ...
提前感谢
推荐答案
你的意思是:
$(function() {
$("#id_birth_date").datepicker({
onSelect: function(dateText, inst) {
var startDate = new Date(dateText);
var selectedYear = startDate.getFullYear(); // selected year
}
});
});
这篇关于如何获得选定的年份在datepicker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文