gpt4 book ai didi

javascript - 带逗号的jquery输入数字

转载 作者:行者123 更新时间:2023-11-30 17:15:59 26 4
gpt4 key购买 nike

我在 jquery 中有一个奇怪的行为。

我想获取输入字段的值(类型数字)。通过示例更容易展示。

当值包含逗号时,该函数会返回一个空字符串。

$("#input[type='number']").on('change',function() {
alert($(this).val());
});

为什么?

提前致谢

最佳答案

HTML5 的 spec不允许逗号:

value = floating-point number
A string representing a number

floating-point numbe r:

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".

关于javascript - 带逗号的jquery输入数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26123810/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com