此代码在年度下拉列表中focusout
时无效,没有任何反应。
在课程.date-of-birth
中,有select
个元素,其中属性name
的值为DateOfBirthYear
。它应该显示消息
$(document).ready(function(){
$( '.date-of-birth > select' ).attr('name','DateOfBirthYear').blur(function() { // also tried with .focusout()
var d = new Date();
d.setDate(d.getDate() - 1)
var date = new Date(d);
var dob = @Model.DateOfBirthMonth+"/"+@Model.DateOfBirthDay+"/"+@Model.DateOfBirthYear;
var dateOfBirth = new Date(dob);
if(dateOfBirth > d){
$('.date-of-birth > .field-validation-error').text('Age cannot be in future');
}
});
});
答案 0 :(得分:0)
$(document).ready(function(){
$( '.date-of-birth > select' ).attr('name','DateOfBirthYear').blur(function() {
var d = new Date();
d.setDate(d.getDate() - 1)
var dob = @Model.DateOfBirthMonth+"/"+@Model.DateOfBirthDay+"/"+@Model.DateOfBirthYear;
var dateOfBirth = new Date(dob);
if(dateOfBirth.getTime() > d.getTime()){
$('.date-of-birth > .field-validation-error').text('Age cannot be in future');
}
});
});