У меня есть событие input
и событие keydown
, привязанные к текстовому полю в угловых значениях. В функции события keydown я получаю объект input
в качестве объекта, представляющего событие в Firefox. В то же время я получаю объект InputEvent
для того же события в Chrome. Я использую поле inputType
в объекте InputEvent
в Chrome, чтобы определить, является ли это событие insertText
, deleteContentBackward
или deleteContentForward
, как указано ниже.
switch(event.inputType) {
case 'insertText':
//do something
break;
case 'deleteContentBackward':
//do something
break;
case 'deleteContentForward':
//do something
break;
}
Проблема в том, что в объекте события, сгенерированном firefox, нет такого поля с именем inputType
.
Объект события в Chrome (71.0.3578.98)
InputEvent {
bubbles: true,
cancelBubble: false,
cancelable: false,
composed: true,
currentTarget: null,
data: null,
dataTransfer: null,
defaultPrevented: true,
detail: 0,
eventPhase: 0,
**inputType: "deleteContentBackward"**,
isComposing: false,
isTrusted: true,
path: (15) [input#search-input.form-control.custom-input.ng-valid.ng-dirty.ng-touched, div.col-md-9.search-input-container, div.col-12.no-padding.search.custom-search-box, div.row.input-group.col-lg-6.col-md-7.col-sm-9.col-xs-12, div.search-section.col-12, app-search-header, div.container, section#homeBanner.intro, app-header, app-root, div.wrapper, body.is-search-open, html.no-js, document, Window],
returnValue: false,
sourceCapabilities: null,
srcElement: input#search-input.form-control.custom-input.ng-valid.ng-dirty.ng-touched,
target: input#search-input.form-control.custom-input.ng-valid.ng-dirty.ng-touched,
timeStamp: 2484875.1999999997,
type: "input",
view: null,
which: 0
}
Ниже приведен тот же объект события в Firefox (65.0b7)
input{
bubbles: true,
cancelBubble: false,
cancelable: false,
composed: true,
currentTarget: null,
defaultPrevented: false,
detail: 0,
eventPhase: 0,
explicitOriginalTarget: <input id="search-input" class="form-control custom-inpu…lid ng-dirty ng-touched" _ngcontent-c10="" type="text" ng-reflect-model="a" placeholder="What are you looking for ?">,
isComposing: false,
isTrusted: true,
layerX: 0,
layerY: 0,
originalTarget: <input id="search-input" class="form-control custom-inpu…lid ng-dirty ng-touched" _ngcontent-c10="" type="text" ng-reflect-model="a" placeholder="What are you looking for ?">,
pageX: 0,
pageY: 0,
rangeOffset: 0,
rangeParent: null,
returnValue: true,
srcElement: <input id="search-input" class="form-control custom-inpu…lid ng-dirty ng-touched" _ngcontent-c10="" type="text" ng-reflect-model="a" placeholder="What are you looking for ?">
target: <input id="search-input" class="form-control custom-inpu…lid ng-dirty ng-touched" _ngcontent-c10="" type="text" ng-reflect-model="a" placeholder="What are you looking for ?">,
timeStamp: 283997,
**type: "input"**, // For insert and delete events this field won't change
view: null,
which: 0
}