[英]Firing an input changed event when decimals are entered into a number input
HTML:
<input id="example" type="number"/>
JS:
$("#example").on("input", function (e) {
debugger;
});
问题如下。 如果该字段的内容为1000
,并且用户输入小数点( .
)以使其为1000.
,则不会触发Chrome中的input
事件。 这是正常现象吗?如果是这样,那么我如何使其触发事件以能够检测到它呢?
如先前的评论中所述,问题在于带点“。”的数字。 最终并没有通过。因此您可以执行以下操作:
$(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.