开发者

How to get val from fileds inside table inside div with JQuery

Can somebody help me how to collect data from input fields from tbl_number in one array array_tbl[number] and object_number in other arrays_object[number] with JQuery when HTML looks like

 <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_开发者_StackOverflow中文版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>


With this code u can get values of inputs that has class 'in' to in array_tbl array

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜