当用户开始在输入字段中输入内容时,我正在开发的 Web 应用程序会生成带有自动填充选项的下拉菜单,如果用户单击其中一个选项,它会使用自动填充文本填充相应的输入字段。
Web 应用程序包含许多发票行,每行都有自己隐藏的自动填写下拉菜单,在自动填写选项可用之前一直隐藏。
如果用户单击自动填充选项,我想使用此自动填充文本更新订单。如果用户没有点击自动填充选项并继续下一个发票行,我仍然想用用户输入的纯文本更新 orderArray。
为此,我尝试使用一个blur
事件,但是无论是否单击了下拉选项,都会触发此模糊事件,并且当且仅当未单击相应行的下拉选项时才需要触发该事件。
我理解为什么模糊事件总是被触发,但是我很难通过分离两个事件并正确更新顺序来克服这个问题。
我很感激任何建议。
提前谢谢了!
$(".dropdown").on(click, ".item-option", function(){
//set item object with dropdown option text
...
...
...
updateOrder(true, item);
$('.dropdown').hide();
});
//if customer enters custom information without clicking on item option
$('.id-input, .name-input, .price-input, .qty-input').blur(function(){
updateOrder(false, {});
});
function updateOrder(clicked, item){
if(clicked==true){
//update order with the item information from the dropdown the user clicked
}else{
//update order by collecting all plaintext user entered into input fields
}
}