JS 키 이벤트와 AngularJS를 혼합하여 사용자가 입력 필드에 비 숫자 키를 입력하지 못하도록합니다 (지시문을 통해).Internet Explorer 11에서 Keyup/Keydown/Keypress 이벤트가 실행되지 않습니다.
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와 지침이 있습니다 : 파이어 폭스와 크롬에서 다음 작품 Internet Explorer는 이러한 이벤트를 무시하는 것 같지만 시계는 잘 작동합니다. IE11과 호환성 문제가 있습니까? 아니면이 문제에 대한 해결 방법을 발견 한 사람이 있습니까?
IE11에서 정상적으로 작동합니까? IE11을 확인할 필요가 없습니다. http://jsfiddle.net/chankeypathak/MJWUw/5/ –
죄송합니다. 지금 수정했습니다. – shanomacadaemia
ngKeypress, ngKeydown 및 ngKeyup을 사용하면 더 좋을 것입니다. – Aray