vue 通过身份证号码判断用户年龄
export default {data() {return(){birthday:’’,//获取出生日期form{idc:‘440983199003214545’//身份证号}}},methods: {queryage() {//得到年龄this.brthday=this.form.idc.substring(6,10)+"-"+this.form.idc.substring...
export default {
data() {
return(){
birthday:’’,//获取出生日期
form{
idc:‘440983199003214545’//身份证号
}
}
},methods: {
queryage() {//得到年龄
this.brthday=this.form.idc.substring(6,10)+"-"+this.form.idc.substring(10,12)+"-"+this.form.idc.substring(12,14);
let age=this.getAge();
console.log(“年龄为”+age);
}
// 判断用户的年龄
getAge(){
let birthdays = new Date(this.birthday.replace(/-/g, “/”));
let d = new Date();
let age =
d.getFullYear() -
birthdays.getFullYear() -
(d.getMonth() < birthdays.getMonth() ||
(d.getMonth() == birthdays.getMonth() &&
d.getDate() < birthdays.getDate())? 1: 0);
return age;
},
}
}
更多推荐
所有评论(0)