Sencha touch 如何在datepickerfield上验证生日?
我想知道datepickerfield的生日,但我不知道试试 我有以下代码: datepickerfieldSencha touch 如何在datepickerfield上验证生日?,sencha-touch,extjs,sencha-touch-2,sencha-architect,Sencha Touch,Extjs,Sencha Touch 2,Sencha Architect,我想知道datepickerfield的生日,但我不知道试试 我有以下代码: datepickerfield { xtype: 'datepickerfield', id: 'dob', name: 'dates', useClearIcon: true, renderData: { placeHolder : 'dd/mm/YYYY' }, label: '*Born of birthday', picker: {
{
xtype: 'datepickerfield',
id: 'dob',
name: 'dates',
useClearIcon: true,
renderData: {
placeHolder : 'dd/mm/YYYY'
},
label: '*Born of birthday',
picker: {
doneButton: 'Select',
cancelButton: 'Cancel',
slotOrder: ['day', 'month', 'year'],
yearFrom: 1925,
yearTo: 2012,
hideOnMaskTap: true,
}
}
和我一样
if(Ext.getCmp('dob').getValue().format('d/m/Y') < new Date().format('d/m/Y')) {
Ext.Msg.alert('Adult')
} else {
Ext.Msg.alert('Minor')
}
if(Ext.getCmp('dob').getValue().format('d/m/Y')
请帮助我。将此侦听器添加到您的
datepickerfield
对象:
listeners:{
change:function(picker, birthDate){
var today = new Date(),
age = today.getFullYear() - birthDate.getFullYear(),
m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
if(age >= 18){
console.log('Adult');
}
else{
console.log('Minor');
}
}
}
侦听器:{
更改:功能(选择器、生日){
var today=新日期(),
年龄=今天。getFullYear()-生日。getFullYear(),
m=today.getMonth()-birthDate.getMonth();
如果(m<0 | |(m==0&&today.getDate()=18岁){
console.log(“成人”);
}
否则{
console.log('Minor');
}
}
}
希望这有帮助