On an input[type='number'] Edge always returns `NaN` for `valueAsNumber`

后端 未结 2 995
难免孤独
难免孤独 2021-01-17 21:32

The following works fine in Chrome and Firefox, however in Edge it will alert NaN no matter the input

相关标签:
2条回答
  • 2021-01-17 22:01

    I don't know why Edge doesn't support valueAsNumber on type="number", but it does support it on range, week, month, and date:

    document.addEventListener('click', function(e) {
      if(e.target.nodeName === 'BUTTON') {
        alert(e.target.previousElementSibling.valueAsNumber);
      }
    });
    <p><input type="range" value="15">          <button>Alert number</button></p>
    <p><input type="week"  value="2015-W50">    <button>Alert number</button></p>
    <p><input type="month" value="2015-12">     <button>Alert number</button></p>
    <p><input type="date"  value="2015-12-12">  <button>Alert number</button></p>

    0 讨论(0)
  • 2021-01-17 22:05

    Microsoft Edge is having broken behavior on valueAsNumber. This is reported as bug #669685. In addition, setting valueAsNumber yields an InvalidStateException.

    This is fixed in Microsoft Edge 17682, currently available in an Windows Insider build.

    0 讨论(0)
提交回复
热议问题