在输入[type ='number']上,Edge总是为`valueAsNumber`返回`NaN` [英] On an input[type='number'] Edge always returns `NaN` for `valueAsNumber`
问题描述
以下在Chrome和Firefox中运行良好,但在Edge中,无论输入是什么,它都会提醒 NaN
The following works fine in Chrome and Firefox, however in Edge it will alert NaN
no matter the input
document.querySelector('button').addEventListener('click', function(){
alert(document.querySelector('input').valueAsNumber);
});
<input type='number' value='34'>
<button>
Alert number
</button>
现在,我不询问如何解决这个问题(使用 parseFloat(el.value)
就可以了),我问的是Edge实现了什么 valueAsNumber
然后,如果最基本的功能似乎不起作用。如在,如何使用此属性根据Edge 。
Now, I am not asking how to fix this (using parseFloat(el.value)
does that trick), I am asking however what Edge did implement valueAsNumber
for then if the most basic function doesn't seem to work. As in, how is one supposed to use this property according to Edge.
推荐答案
Microsoft Edge是在 valueAsNumber
上破坏了行为。这被报告为错误#669685 。此外,设置 valueAsNumber
会产生InvalidStateException。
Microsoft Edge is having broken behavior on valueAsNumber
. This is reported as bug #669685. In addition, setting valueAsNumber
yields an InvalidStateException.
这在Microsoft Edge 17682中得到修复,目前在Windows中可用内幕构建。
This is fixed in Microsoft Edge 17682, currently available in an Windows Insider build.
这篇关于在输入[type ='number']上,Edge总是为`valueAsNumber`返回`NaN`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!