我有對象列表與關鍵值& pair.when我分離那些顯示在一個特定的字段中的每個信息。 我收到類型錯誤data.validation [i] .user未定義 但我已檢查變量已被賦值。沒有在JavaScript值(未定義)
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>");
}
}
$( 「#移動」)表示輸入字段Id
任何想法都熱烈歡迎
JavaScript數組索引開始從0到長度-1; – xff1874
謝謝@ xff1874.我知道一個。但我已經錯過了那個東西 – user2742540