我知道這不應該很難,但是我需要另一雙眼睛,因爲我正在靠牆敲打我的頭。無法將嵌套表格輸入元素嵌入到jQuery數組中
我有一個嵌套表與ID如:
<table id="dwMeasurements_0">
<tbody>
<tr id="tDim_0">
<td colspan="2">
<strong>Total Wall Length: </strong>
</td>
<td>
<input type="text" id="Msr_0_T1" class="dwInput" value="0"> Inches and </td>
<td>
<input type="text" id="Msr_0_T2" class="dwInput" style="margin-left:2px;" value="0"> 16ths</td>
</tr>
<tr>
<td colspan="4">
<hr>
</td>
</tr>
<tr id="lDim_0_0">
<td>
<select id="ItemType_0_0">
<option>Item Type</option>
<option>Door</option>
<option>Window</option>
<option>Other</option>
</select>
</td>
<td>
<label>L-Dim: </label>
</td>
<td>
<input type="text" id="Msr_0_0_A1" class="dwInput" value="0"> Inches and </td>
<td>
<input type="text" id="Msr_0_0_A2" class="dwInput" style="margin-left:2px;" value="0"> 16ths</td>
</tr>
//MORE ROWS HERE//
</table>
我的jQuery序列化文本輸入和選擇的元件如下:
var MeasureRowCount = $("[id^='MeasureRow_']").length; //Populated by counting parent rows
var htmlOutput = '';
var rowInputs,rowSelects;
for(var r=0;r < MeasureRowCount;r++){
rowInputs = $('#dwMeasurements_'+r+' :input').serializeArray();
rowSelects = $('#dwMeasurements_'+r).find('select').serializeArray();
$.each(rowSelects, function(i, eSelectItem){
esName = eSelectItem.name;
esVal = eSelectItem.value;
htmlOutput += //name and value from above with markup
}
}
// htmlOutput to DOM here with markup
我試圖多種方法來收集輸入元素並且不工作。陣列空了。即使表嵌套,不應該它工作,因爲我直接調用嵌套的表ID?
jsfiddle和控制檯消息請 – mplungjan 2013-02-19 15:01:49
使用像'[id^='MeasureRow _']'這樣的選擇器是一個很好的指示器,您應該使用普通的類。 – Blazemonger 2013-02-19 15:04:01
添加到@Blazemonger所說的內容中,我沒有看到您在'MeasureRow_something'中使用任何標識的位置,MeasureRowCount的計數將爲0 – Trufa 2013-02-19 15:07:20