我有这个html
<div class="table-responsive table-responsive-data2">
<table class="table table-data2" id="resulttable" style="display: block;">
<thead>
<tr>
<th>NSN</th>
<th>Name</th>
<th>QTY</th>
<th>Price ($)</th>
<th>Manufacturer</th>
<th>Part Number</th>
<th>Shipping</th>
</tr>
</thead>
<tbody id="producttable">
<!-- -->
<form id="myform0"></form>
<tr class="tr-shadow">
<td style="width: 90px;">
<div>123
</div>
<div>
<br>
<button type="button" class="btn btn-secondary mb-1 btn-sm" data-toggle="modal" data-target="#productModal" onclick="showproductmodal(123)">
Add Photos
</button>
</div>
</td>
<td>
<span class="status--process">
<input class="au-input au-input--sm" id="Nomenclature" type="text" name="search" placeholder="Search for datas & reports..." style="width: 90px;">
</span>
</td>
<td class="desc">
<input class="au-input au-input--sm " id="Qty" type="text" name="search" placeholder="i.e. 20 EA" style="width: 100px;">
</td>
<td class="desc">
<input class="au-input au-input--sm" id="Price" type="text" name="search" placeholder="i.e 900" style="width: 90px;">
</td>
<td>
<span class="status--process">
<input class="au-input au-input--sm" type="text" name="search" placeholder="Search for datas & reports..." style="width: 90px;">
</span>
</td>
<td class="desc">
<input class="au-input au-input--sm" type="text" name="search" placeholder="Search for datas & reports..." style="width: 90px;">
</td>
<td class="status--process">
<input class="au-input au-input--sm" type="text" name="search" placeholder="shipping cost" style="width: 120px; height: 30px;"><br>
<select name="selectSm" id="SelectLm" class="form-control-sm form-control" style="width: 120px;">
<option value="0">Please select</option>
<option value="1">Option #1</option>
<option value="2">Option #2</option>
<option value="3">Option #3</option>
<option value="4">Option #4</option>
<option value="5">Option #5</option>
</select>
</td>
<td>
<button type="button" class="btn btn-primary btn-md" onclick="postitem(0)">Submit</button>
</td>
</tr>
<tr class="spacer"></tr>
<form id="myform1"></form>
<tr class="tr-shadow">
<td style="width: 90px;">
<div>343
</div>
<div>
<br>
<button type="button" class="btn btn-secondary mb-1 btn-sm" data-toggle="modal" data-target="#productModal" onclick="showproductmodal(343)">
Add Photos
</button>
</div>
</td>
<td>
<span class="status--process">
<input class="au-input au-input--sm" id="Nomenclature" type="text" name="search" placeholder="Search for datas & reports..." style="width: 90px;">
</span>
</td>
<td class="desc">
<input class="au-input au-input--sm " id="Qty" type="text" name="search" placeholder="i.e. 20 EA" style="width: 100px;">
</td>
<td class="desc">
<input class="au-input au-input--sm" id="Price" type="text" name="search" placeholder="i.e 900" style="width: 90px;">
</td>
<td>
<span class="status--process">
<input class="au-input au-input--sm" type="text" name="search" placeholder="Search for datas & reports..." style="width: 90px;">
</span>
</td>
<td class="desc">
<input class="au-input au-input--sm" type="text" name="search" placeholder="Search for datas & reports..." style="width: 90px;">
</td>
<td class="status--process">
<input class="au-input au-input--sm" type="text" name="search" placeholder="shipping cost" style="width: 120px; height: 30px;"><br>
<select name="selectSm" id="SelectLm" class="form-control-sm form-control" style="width: 120px;">
<option value="0">Please select</option>
<option value="1">Option #1</option>
<option value="2">Option #2</option>
<option value="3">Option #3</option>
<option value="4">Option #4</option>
<option value="5">Option #5</option>
</select>
</td>
<td>
<button type="button" class="btn btn-primary btn-md" onclick="postitem(1)">Submit</button>
</td>
</tr>
<tr class="spacer"></tr>
<form id="myform2"></form>
<tr class="tr-shadow">
<td style="width: 90px;">
<div>212
</div>
<div>
<br>
<button type="button" class="btn btn-secondary mb-1 btn-sm" data-toggle="modal" data-target="#productModal" onclick="showproductmodal(212)">
Add Photos
</button>
</div>
</td>
<td>
<span class="status--process">
<input class="au-input au-input--sm" id="Nomenclature" type="text" name="search" placeholder="Search for datas & reports..." style="width: 90px;">
</span>
</td>
<td class="desc">
<input class="au-input au-input--sm " id="Qty" type="text" name="search" placeholder="i.e. 20 EA" style="width: 100px;">
</td>
<td class="desc">
<input class="au-input au-input--sm" id="Price" type="text" name="search" placeholder="i.e 900" style="width: 90px;">
</td>
<td>
<span class="status--process">
<input class="au-input au-input--sm" type="text" name="search" placeholder="Search for datas & reports..." style="width: 90px;">
</span>
</td>
<td class="desc">
<input class="au-input au-input--sm" type="text" name="search" placeholder="Search for datas & reports..." style="width: 90px;">
</td>
<td class="status--process">
<input class="au-input au-input--sm" type="text" name="search" placeholder="shipping cost" style="width: 120px; height: 30px;"><br>
<select name="selectSm" id="SelectLm" class="form-control-sm form-control" style="width: 120px;">
<option value="0">Please select</option>
<option value="1">Option #1</option>
<option value="2">Option #2</option>
<option value="3">Option #3</option>
<option value="4">Option #4</option>
<option value="5">Option #5</option>
</select>
</td>
<td>
<button type="button" class="btn btn-primary btn-md" onclick="postitem(2)">Submit</button>
</td>
</tr>
<tr class="spacer"></tr>
</tbody>
</table>
并且我有一个从动态创建的html触发的函数。
function postitem(index) {
var formid='#myform'+index
$('input').each(function(index){
console.log($(this).val());
});
}
选择器$(' input ')捕获html中的所有输入值,我真正想要的是让它只捕获给定#id内的输入。所以我试着
$('#myform1 input').each(function(index){
console.log($(this).val());
});
和
$(formid).('input')
它们都没有产生任何结果。如何实现在div id中检索输入?
发布于 2018-07-10 19:04:56
您可以在不使用父$("#idInput")
的情况下直接访问输入,或者可以使用$('#myform1 #idInput')
通过父use访问它。但是要确保在生成时已经定义了元素的ids。
还有另一种方法,你可以使用它作为数组$('#myform1 input')[index]
。注意:索引应该是您的输入所需的出现次数。
https://stackoverflow.com/questions/51263501
复制相似问题