gpt4 book ai didi

javascript - 使用 Javascript 按下 Tab 键时出现问题

转载 作者:行者123 更新时间:2023-12-03 03:11:03 25 4
gpt4 key购买 nike

当我在金额字段中输入内容并按 tab 意味着它将调用该函数时,我想调用 add() 函数。但金额旁边的字段处于只读模式,因此它无法正确调用该函数。我尝试了如下代码,请任何人建议我解决方案:

$('#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>

enter image description here

最佳答案

显然,在字段失去焦点后会调用 keyup。因此,在金额字段上注册没有帮助。引用:

jQuery: keyup for TAB-key?

此外,是否有任何要求,例如 add() 函数必须仅在按 Tab 时发生,而不是在用户单击金额字段之外的任何地方时发生?或者如果发生在场上失去焦点也没关系吗?就像单击字段上的某些位置一样...包括按 TAB 键...

关于javascript - 使用 Javascript 按下 Tab 键时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46946002/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com