使用js验证年龄是否有18岁
<div class="renzhenglx_div">
<div class="renzheng_left_div" style="line-height: 20px">
生日:</div>
<div class="renzheng_right_div">
<select name="Date_Year" id="Date_Year" class="select_b_div" style="width: auto;">
</select> 年
<select name="birthday_m" id="birthday_m" class="select_b_div" style="width: auto;">
</select> 月
<select name="birthday_d"" id="birthday_d" class="select_b_div" style="width: auto;">
</select> 日
</div>
</div>
[解决办法]
var date = new Date(); var sYear = $("#Date_Year").val(); var sMonth = $("#birthday_m").val(); var sDay = $("#birthday_d").val(); var dYear = date.getFullYear(); var dMonth = date.getMonth()+1; var dDay = date.getDate(); if((Number(dDay)-Number(sDay))<0) { dMonth -= 1; } if((Number(dMonth)-Number(sMonth))<0) { dYear -= 1; } if((Number(dYear)-Number(sYear))>=18) { alert("已满18岁"); } else { alert("未满18岁"); }