gpt4 book ai didi

javascript - 在 IE8 中按 Enter 键意外触发 ng-click

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:46:00 24 4
gpt4 key购买 nike

我在 ng-repeat 中嵌套了一个简单的 ng-click 按钮,但没有 <form>在当前页面。

<tr ng-repeat="product in catalog | limitTo: total track by $index" ng-class="{highlight: product==selected}">
<td class="highlight-hide">
<div ng-if="canDoSelfOrdering">
<button class="btn btn-mini" ng-click="callPricing(product)">Price & Order</button>
</div>
</td>
<!-- other td -->
</tr>

当目录数组更新并且用户在没有关注任何输入的情况下按下 ENTER 时。最后一个按钮元素 ng-click="callPricing(product)"无意中触发。

我在按下 Enter 键之前尝试观看 document.activeElement 它是 <body>

如何防止这种情况?

最佳答案

Internet Explorer documentation表示在 IE8 标准模式下,默认按钮值为提交。

If the ENTER key is pressed while a user is viewing a form that contains a Submit button, the form is submitted.

虽然您没有要提交的任何表格,但我猜 IE8 不会检查它。只需尝试将您的按钮类型显式写为 button 即可。

<button type="button" class="btn btn-mini" ng-click="callPricing(product)">Price & Order</button>

关于javascript - 在 IE8 中按 Enter 键意外触发 ng-click,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26904616/

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