当用户在输入类型编号上输入小数时,事件返回空值 [英] Event return null value when user enter decimal on input type number
问题描述
编辑可在Firefox上运行,只有Chrome错误(也许还有其他)
Edit working on Firefox, only Chrome bug (and maybe others)
我尝试从简单的<input type="number" step="any" />
获取所有事件:
I try to get all event from a simple <input type="number" step="any" />
:
$('input[type=number]').on('input', function() {
$('#value').text($(this).val())
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number" step="any"/>
<br/>
<strong>Value:</strong> <span id="value"></span>
当我按下或更新数字时,所有附加项会附加好.但是,当我尝试放置小数点.
时,其值为null
.
All append good when I press, or update the number. But when I try to put a decimal point .
the value is null
.
我在这里使用jQuery,但是问题与Vanilla JS相同.
I use jQuery here, but the problem is the same with Vanilla JS.
推荐答案
我认为这与input
字段的type
有关,decimal point
(点)不是数字,但是数字是必需的,所以我想这是矩阵中的小故障.
i think it is issue with type
of input
field, decimal point
(the dot) is not a number but it is necessary for numbers, so i guess it is the glitch in the matrix.
这是一个小提琴,其中类型是文本,可以正常工作.
here is a fiddle where type is text and it is working fine.
这篇关于当用户在输入类型编号上输入小数时,事件返回空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!