[英]Keyup/Keydown/Keypress events not firing in Internet Explorer 11
我混合使用JS鍵事件和AngularJS,以防止用戶在輸入字段中輸入非數字鍵(通過指令)。 盡管以下各項在Firefox和Chrome中均可運行,但Internet Explorer似乎忽略了這些事件:
app.directive("numberField", function ()
{
return {
restrict: "E",
scope:
{ },
link: function (scope, element, attrs, ctrl)
{
$(element).on('keydown', function (event)
{
var key = event.which || event.keyCode;
if (!event.shiftKey && !event.altKey && !event.ctrlKey &&
// numbers
key >= 48 && key <= 57 ||
// Numeric keypad
key >= 96 && key <= 105 ||
// Backspace and Tab and Enter
key == 8 || key == 9 || key == 13 ||
// Home and End
key == 35 || key == 36 ||
// left and right arrows
key == 37 || key == 39 ||
// Del and Ins
key == 46 || key == 45 ||
//Period and Decimal Point
key == 110 || key == 190)
return true;
return false;
});
},
templateUrl: "DirectiveTemplate/NumberField"
};
});
也有類似ng-keyup和ng-keydown的AngularJS指令被類似地忽略,但是任何其他AngularJS功能(例如手表)都可以正常工作。 我不知道與IE11的一些兼容性問題嗎? 還是有人發現此問題的解決方法?
事實證明,這是我的屬性命名不佳的情況。 我使用“禁用”作為要作為參數傳遞給指令的屬性,而IE無法區分標准HTML禁用和指令的自定義屬性。 重命名解決了該問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.