当我在金额字段中键入内容时,我想调用add()函数,而按Tab键意味着它会调用它。但是金额旁边的字段处于只读模式。所以它没有正确地调用该函数。我尝试了下面的代码,请有人建议我解决。,
$('#price_1').on( 'keyup', function( e ) {
if( e.which == 9 ) {
var i=$('table tr').length;
html = '<tr>';
html += '<td><input class="case" type="checkbox"/></td>';
html += '<td><input type="text" data-type="productName" autocomplete="" name="itemName[]" id="itemName_'+i+'" id="productList" class="form-control autocomplete_txt item2" tabindex="0" value=""style="text-align:center;" autofocus></td>';
html += '<td><input type="number" name="quantity[]" id="quantity_'+i+'" class="form-control changesNo" autocomplete="off" tabindex="0" onkeypress="return IsNumber(event);" ondrop="return false;" onpaste="return false;"></td>';
html += '<td><input type="number" name="price[]" id="price_'+i+'" class="price1 form-control changesNo" autocomplete="off" tabindex="0" onkeypress="return IsNumber(event);" ondrop="return false;" onpaste="return false;"></td>';
html += '<td><input type="number" name="total[]" id="total_'+i+'" class="form-control totalLinePrice" autocomplete="off" tabindex="-1" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" readonly></td>';
html += '</tr>';
$('table').append(html);
$(".item2").autocomplete({
source: "https://www.duminex.com/product/search",
select: function( event, ui ) {
var a = i - 1;
$('#id').val(ui.item.id);
$('#price_' + a).val(ui.item.price);
}
});
i++;
}
});
<td><input type="text" tabindex="6" name="price[]" id="price_1" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumber(event);" onpaste="return false;" required="required" ></td>
<td><input type="text" name="total[]" id="total_1" class="form-control totalLinePrice" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" required="required" ></td>
答案 0 :(得分:1)
显然,在字段失去焦点后调用keyup。因此,在金额字段上注册将无济于事。参考:
此外,是否有任何要求,例如,add()函数必须仅在Tab按下时发生,而不是如果用户点击金额字段之外的任何地方?或者如果在失去焦点的领域发生这种情况会好吗?就像点击场上的某些地方一样......包括TAB按......