Firefox:在keydown事件对象中没有名为inputType的字段

时间:2019-01-03 08:04:41

标签: javascript angular firefox cross-browser

我有一个input事件和一个keydown事件绑定到有角的文本框。在keydown事件函数中,我将一个input对象作为代表firefox中事件的对象。同时,我在Chrome中收到同一事件的InputEvent对象。我正在使用chrome中inputType对象中的InputEvent字段来确定它是insertTextdeleteContentBackward还是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
    }

1 个答案:

答案 0 :(得分:1)

可以在this way, in a jquery environment.

中解决此问题

在Angular上,我以这种方式解决了这个问题。

aws route53 list-resource-record-sets --hosted-zone-id <relevant_zone_id> --query "ResourceRecordSets[?AliasTarget.DNSName == 'abeXXXXXXXXXXX-12345XX.us-east-2.elb.amazonaws.com.']"