我有以下 JSON 对象:
{
"a1_1_on" : "on",
"a1_1_thr" : "",
"a1_2_on" : "on",
"a1_2_thr" : "",
}
我想使用 for 循环来检查字段,例如:
for (var i=1; i<2; i++) {
//alarm
var al = 'ai_' + i + '_on';
//alarm threshold
var althr = 'ai_' + i + '_thr'
//console.log(form_infos.al);
if(form_infos.al == "on" && form_infos.althr == "") {
alert("Alarm for Analog " + i + "is on and you did not specified a threshold. Please specify a threshold before submittiing");
return false;
}
}
但它表明undefined
我是否这样做console.log(form_infos.al)
。有什么建议么?