我有以下html字段,我需要检查输入值是浮点数还是int值,
$(document).ready(function(){ $('.check_int_float').focusout(function(){ var value = this.value if (value is float or value is int) { // do something } else { alert('Value must be float or int'); } }); });
那么如何在jquery中检查值是float还是int.
我需要找到/检查这两种情况,无论是浮点数还是int,因为稍后如果值为float
i,我会将它用于某种目的,类似地int
.
使用typeof
检查类型,然后value % 1 === 0
找出INT为波纹管,
if(typeof value === 'number'){ if(value % 1 === 0){ // int } else{ // float } } else{ // not a number }