我有一个订购零件的表格,当您键入文章代码时,您可以在其中通过ajax显示有关零件的信息。该数据显示在表格中,接下来您可以在表格中的可用供应商之间进行选择,然后单击要选择的供应商。
之后,您可以选择添加更多重复此过程的零件。
因为当您选择添加更多零件时,输入字段是动态添加的,所以我需要知道正在使用哪个输入。通常情况下,您总是使用最后一个输入,但是可能要更改预先输入的商品代码,因此,在这种情况下,我想让用户选择将供应商更改为相应的输入最后。
我想出了选择具有焦点事件的输入的想法,问题是当输入被聚焦时,而不是我要去桌子上并单击另一个供应商时,输入失去了焦点,因此不知道在哪里放置价值。
HTML(仅相关代码)
Article code <input name='article_code[]' type='text' class='article_code'>
Description <input type='text' class='article_description' name='article_description[]' value='No articlecode specified' READONLY>
Supplier <input type='text' class='supplier_output' name='supplier_outputt[]' value='No supplier specified' READONLY>
<table id='supplier_table' class='sortable' width='100%'>
<THEAD>
<tr valign='top'>
<th width='25%'>Supplier</th>
<th width='25%'>Mainsupplier</th>
<th width='25%'>Price</th>
<th width='25%'>Article code</th>
</tr>
</THEAD>
<TBODY >
</TBODY>
</table>
的JavaScript
$('#supplier_table').on('click', 'tbody tr', function(){
var tableData = $(this).children('td').map(function() {
return $(this).text();
}).get();
var selectedSupplier = $.trim(tableData[0]);
var supplier_val;
if($('.article_code').is(':focus')){
supplier_val = $(this).closest('tr').next().next().find('.supplier_output');
$(supplier_val).val(selectedSupplier);
} else {
$('.supplier_output').last().val(selectedSupplier);
}
});
因此,基本上我需要将焦点上的最后一个元素的值存储起来。
不知道我是否正确理解您的问题。但是也许我可以帮助您从另一个方向思考。使用模糊事件。然后将最后一个模糊的文章代码存储在last_val变量中:
$('.article_code').on('blur', function(){ last_val = this.value; })
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句