[英]Firing an input changed event when decimals are entered into a number input
The HTML: HTML:
<input id="example" type="number"/>
The JS: JS:
$("#example").on("input", function (e) {
debugger;
});
The issue is as follows. 问题如下。 If the content of the field is
1000
, and the user enters a decimal ( .
), to make it 1000.
, it does not fire the input
event in Chrome. 如果该字段的内容为
1000
,并且用户输入小数点( .
)以使其为1000.
,则不会触发Chrome中的input
事件。 Is this normal, and if so, then how can I make it fire an event to be able to detect it? 这是正常现象吗?如果是这样,那么我如何使其触发事件以能够检测到它呢?
As mentioned in previous comment, the problem is that a number with dot "." 如先前的评论中所述,问题在于带点“。”的数字。 in the end doesn't passed in. So here is something you can do:
最终并没有通过。因此您可以执行以下操作:
$(function(){ var lastNum; $("#example").on("input", function (e) { if(this.value.length>0)lastNum=this.value;//if value passed in correctly - update it console.debug(lastNum);//Do anything with the lastNum }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input id="example" type="number"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.