[英]Cannot get raw value from (including dot(.)) from HTML input type number
当我点击输入<input type="number" id="n" />
; 在输入的keypress
功能上键入一些keypress
。 然后输入.
虽然它显示在输入上,但我看不到.
在$('#n').val()
。
例如,键入: 123.
然后$('#n').val()
仅返回123
。
是否有任何<input type="number" />
属性可以获取其raw value
123.
而不是123
?
$("#n").on("keypress", function(event) { console.log($("#n").val()); });
<script src="https://code.jquery.com/jquery-2.1.4.js"></script> <input type="number" pattern="[0-9]{1,2}([\\.][0-9]{1,2})?" id="n" step="0.01" />
更新:
input
必须具有数字类型,以使其只能在移动网络上的软键盘上显示数字输入。 它应检查99.99模式并按以下方式工作:
没有检测到存在点(。),我怎么能检测到键入Multiple的情况.
连续地?
我本人已经较早遇到了这个问题。 也许这可以帮助:
$("#n").on("keyup", function(event){ var val = $('#n').val(); if(event.keyCode == 190) { val+='.'; } console.log(val); });
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>JS Bin</title> </head> <body> <script src="https://code.jquery.com/jquery-2.1.4.js"></script> <input type="number" id="n" /> </body> </html>
<input type="number"
min="0"
max="999"
step="0.000001"
pattern="[0-9]{1,2}([\.][0-9]{1,2})?"
id="n" />
这应该可以解决您的问题。 Use FocusOut event to capture the value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.