2011-09-27 42 views
0
獲得VAL內表內的div

有人可以幫助我如何收集從tbl_number輸入字段中的數據在一個陣列array_tbl [數字]和object_number其他arrays_object [數字]使用jQuery時HTML看起來像如何從的Fileds使用jQuery

<div id="devices" style="width:95%;"> 
<div id="device_1" style="background-color:#858585;"> 
<table id="tbl_device_1"> 
<tbody> 
<tr> 
<th>Slave</th> 
<th>Instance</th> 
<th>Object Name</th> 
<th>Model Name</th> 
<th>Delete</th> 
<th>Add Object</th> 
</tr> 
<tr> 
<td> 
<input id="slave_address_1" class="in" type="text"/> 
</td> 
<td> 
<input id="instance_1" class="in" type="text"/> 
</td> 
<td> 
<input id="object_name_1" class="in" type="text"/> 
</td> 
<td> 
<input id="model_name_1" class="in" type="text"/> 
</td> 
<td> 
<input class="btn_del" type="button" onclick="$('#device_1').remove();" title="Delete"/> 
</td> 
<td> 
<input class="btn_add" type="button" onclick="add_object_row(1);" title="Add new object" style="float:none;"/> 
</td> 
</tr> 
</tbody> 
</table> 
<br> 
<div id="device_objects_1" style="width:100%;"> 
<table id="object_1" style="margin-left:30px;"> 
<tbody> 
<tr> 
<th>Type</th> 
<th>Instance</th> 
<th>Object Name</th> 
<th>Val Type</th> 
<th>Position</th> 
<th>Units</th> 
<th>Quot</th> 
<th>Shift</th> 
<th>Delete</th> 
</tr> 
<tr> 
<td> 
<input id="type_1" class="in_short" type="text"/> 
</td> 
<td> 
<input id="instance_1" class="in_short" type="text"/> 
</td> 
<td> 
<input id="object_name_1" class="in_short" type="text"/> 
</td> 
<td> 
<input id="val_type_1" class="in_short" type="text"/> 
</td> 
<td> 
<input id="position_1" class="in_short" type="text"/> 
</td> 
<td> 
<input id="units_1" class="in_short" type="text"/> 
</td> 
<td> 
<input id="quot_1" class="in_short" type="text"/> 
</td> 
<td> 
<input id="shift_1" class="in_short" type="text"/> 
</td> 
<td> 
<input class="btn_del" type="button" onclick="$('#object_1').remove();"/> 
</td> 
</tr> 
</tbody> 
</table> 
<table id="object_1" style="margin-left:30px;"> 
<tbody> 
<tr> 
<th>Type</th> 
<th>Instance</th> 
<th>Object Name</th> 
<th>Val Type</th> 
<th>Position</th> 
<th>Units</th> 
<th>Quot</th> 
<th>Shift</th> 
<th>Delete</th> 
</tr> 
<tr> 
<td> 
<input id="type_2" class="in_short" type="text"/> 
</td> 
<td> 
<input id="instance_2" class="in_short" type="text"/> 
</td> 
<td> 
<input id="object_name_2" class="in_short" type="text"/> 
</td> 
<td> 
<input id="val_type_2" class="in_short" type="text"/> 
</td> 
<td> 
<input id="position_2" class="in_short" type="text"/> 
</td> 
<td> 
<input id="units_2" class="in_short" type="text"/> 
</td> 
<td> 
<input id="quot_2" class="in_short" type="text"/> 
</td> 
<td> 
<input id="shift_2" class="in_short" type="text"/> 
</td> 
<td> 
<input class="btn_del" type="button" onclick="$('#object_1').remove();"/> 
</td> 
</tr> 
</tbody> 
</table> 
</div> 
</div> 
<div id="device_6" style="background-color:#C2C2C2;"> 
<table id="tbl_device_6"> 
<tbody> 
<tr> 
<th>Slave</th> 
<th>Instance</th> 
<th>Object Name</th> 
<th>Model Name</th> 
<th>Delete</th> 
<th>Add Object</th> 
</tr> 
<tr> 
<td> 
<input id="slave_address_6" class="in" type="text"/> 
</td> 
<td> 
<input id="instance_6" class="in" type="text"/> 
</td> 
<td> 
<input id="object_name_6" class="in" type="text"/> 
</td> 
<td> 
<input id="model_name_6" class="in" type="text"/> 
</td> 
<td> 
<input class="btn_del" type="button" onclick="$('#device_6').remove();" title="Delete"/> 
</td> 
<td> 
<input class="btn_add" type="button" onclick="add_object_row(6);" title="Add new object" style="float:none;"/> 
</td> 
</tr> 
</tbody> 
</table> 
<br> 
<div id="device_objects_6" style="width:100%;"> 
<table id="object_6" style="margin-left:30px;"> 
<tbody> 
<tr> 
<th>Type</th> 
<th>Instance</th> 
<th>Object Name</th> 
<th>Val Type</th> 
<th>Position</th> 
<th>Units</th> 
<th>Quot</th> 
<th>Shift</th> 
<th>Delete</th> 
</tr> 
<tr> 
<td> 
<input id="type_3" class="in_short" type="text"/> 
</td> 
<td> 
<input id="instance_3" class="in_short" type="text"/> 
</td> 
<td> 
<input id="object_name_3" class="in_short" type="text"/> 
</td> 
<td> 
<input id="val_type_3" class="in_short" type="text"/> 
</td> 
<td> 
<input id="position_3" class="in_short" type="text"/> 
</td> 
<td> 
<input id="units_3" class="in_short" type="text"/> 
</td> 
<td> 
<input id="quot_3" class="in_short" type="text"/> 
</td> 
<td> 
<input id="shift_3" class="in_short" type="text"> 
</td> 
<td> 
<input class="btn_del" type="button" onclick="$('#object_6').remove();"/> 
</td> 
</tr> 
</tbody> 
</table> 
</div> 
</div> 
</div> 
+1

把表單中的元素(把它放在表外),那麼你就可以訪問所有通過名稱或id作爲表單屬性的輸入,或迭代表單的* elements * collect直接得到它們。 – RobG

回答

1

有了這個代碼u能得到的輸入值有「在」類array_tbl陣列

var array_tbl = [] 
$('.in').each(function(){ 
    array_tbl.push($(this).val()) 
})