我有这样的jquery datepicker
$birth.datepicker({
onSelect: function(dateText, inst) {
$(this).parent().find("label#error").html("");
$gender.focus();
},
yearRange: '1950:2006',
changeMonth: true,
changeYear: true,
showOtherMonths: true,
selectOtherMonths: true,
dateFormat: 'yy-mm-dd',
defaultDate: new Date(2006,01,01),
});
我正在尝试修改此代码,以便将当前年份减去 10,如下所示
$birth.datepicker({
var currentYear = new Date();
onSelect: function(dateText, inst) {
$(this).parent().find("label#error").html("");
$gender.focus();
},
yearRange: '1950:document.write(currentYear.getFullYear() - 10)',
changeMonth: true,
changeYear: true,
showOtherMonths: true,
selectOtherMonths: true,
dateFormat: 'yy-mm-dd',
defaultDate: new Date(2006,01,01),
});
上面的代码不起作用,它破坏了我的日期选择器......有没有更好的方法来做到这一点?