我有一堆用户输入要从 javascript 存储。我喜欢遍历一些计数器,因为它存储输入而不是一次分配一个。这是指定元素 ID 的正确语法吗?目前它对我不起作用,并抱怨例如 catMaxInput: [Exception: ReferenceError: catMaxInput is not defined]
var catInput = [], catMaxInput = [], catCostSFHR = [], catOccHRStart=[], catOccHREnd =[];
var z = 1;
for (var i=0; i<3; i++){
catMaxInput[i] = (Math.round(parseFloat(document.getElementById("cat\"" + z + "\"Max").value)));
z++;
}
for (var c=0; c<3; c++){
catTotalArea[c] = (Math.round(parseFloat(document.getElementById("cat\"" + z + "\"TotalArea").value)));
z++;
}
到目前为止,这是表格:
<tr>
<td>CAT 1</td>
<td><input name="data1Max4" type="text" id="cat1Max" value="20" /></td>
<td><input name="data1Max7" type="text" id="cat1TotalArea" value="50,000 SF" /></td>
<td><input name="data1Max10" type="text" id="cat1CostSFHR" value="$ 100.00" /></td>
<td><input name="data1Max13" type="text" id="cat1OccHRStart" value="6:00am" /></td>
<td><input name="data1Max16" type="text" id="cat1OccHREnd" value="12:00pm" /></td>
</tr>
<tr>
<td>CAT B</td>
<td><input name="data2Max5" type="text" id="cat2Max" value="70" /></td>
<td><input name="data2Max8" type="text" id="cat2TotalArea" value="20,000 SF" /></td>
<td><input name="data2Max11" type="text" id="cat2CostSFHR" value="$ 50.00" /></td>
<td><input name="data2Max14" type="text" id="cat2OccHRStart" value="12:00pm" /></td>
<td><input name="data2Max17" type="text" id="cat2OccHREnd" value="8:00pm" /></td>
</tr>
<tr>
<td>CAT C</td>
<td><input name="data3Max6" type="text" id="cat3Max" value="100" /></td>
<td><input name="data3Max9" type="text" id="cat3TotalArea" value="30,000 SF" /></td>
<td><input name="data3Max12" type="text" id="cat3CostSFHR" value="$ 0.00" /></td>
<td><input name="data3Max15" type="text" id="cat3OccHRStart" value="8:00pm" /></td>
<td><input name="data3Max18" type="text" id="cat3OccHREnd" value="6:00am" /></td>
</tr>