我有具有键值和对的对象列表。当我将它们分开以在特定字段上显示每个信息时。我收到类型错误data.validation[i].user is undefined 但我检查了变量是否已分配值。
var data = {validation:[
{"user":"user may not be empty"},
{"date":"Date may not be null"},
{"mobile":"passengerMobile may not be empty"},
{"mobileSize":"passengerMobile size must be greater than 11"},
{"name":"passengerName may not be empty"},
{"nameSize":"passengerName size must be between 2 and 30"},
]};
var size = data.validation.length;
for(var i =0;i<=size;i++){
if(data.validation[i].user){
$("#username").html("<p>"+data.validation[i].user+"</p>");
}
if($("#mobile").val().length == 0){
$("#mobilesize").html("<p>"+data.validation[i].mobile+"</p>");
}
else if($("#mobile").val().length >= 1){
$("#mobilesize").html("<p>"+data.validation[i].mobilesize+"</p>");
}
}
$("#mobile") 表示输入字段Id
欢迎任何想法