AngularJS Tab键按下阻止默认行为

3

你好,我有一个输入字段,当按下Tab键时会调用add_plu()函数。虽然它能够工作,但它会移动到页面的下一个元素(Tab键的默认行为)。

我该如何阻止Tab键的默认行为?以下是我的代码:

   <input class="order-input-plu form-control" ng-model="order.orderwindow.add_field" ui-keydown="{ 'tab':'add_plu(order.orderwindow.add_field)'}">
1个回答

5
ui-key*指令在作用域中提供事件,因此您可以将$event添加到函数调用中并对其进行操作。
ui-keydown="{ 'tab':'add_plu(order.orderwindow.add_field, $event)'}"

然后修改您的add_plu函数以接受$event参数,并调用$event.preventDefault()。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接