我在jquery中有一种奇怪的行为。
我想获取输入字段的值(类型编号)。用一个例子来展示它会更容易。
当值包含逗号时,函数会返回空字符串。
$("#input[type='number']").on('change',function() {
alert($(this).val());
});
为什么?
提前致谢
答案 0 :(得分:3)
HTML5' spec不允许使用逗号:
value = floating-point number
A string representing a number
A floating-point number consists of the following parts, in exactly the following order:
1. Optionally, the first character may be a "-" character.
2. One or more characters in the range "0—9".
3. Optionally, the following parts, in exactly the following order:
1. a "." character
2. one or more characters in the range "0—9"
Optionally, the following parts, in exactly the following order:
1. a "e" character or "E" character
2. optionally, a "-" character or "+" character
3. One or more characters in the range "0—9".
答案 1 :(得分:-1)
将此添加到输入:step =“0.01”
如下所示:
<input type="number" step="0.01" />
然后0.10将有效,如果您的操作系统使用以逗号分隔的小数,我不确定逗号是否会被视为有效。