Javascript 定义插入字符串或int的类型

Javascript 定义插入字符串或int的类型,javascript,Javascript,如何定义在文本字段中键入的变量类型?我希望在文本字段中键入一些内容,当您按下搜索按钮时,根据类型,它将显示来自数据库的不同结果 if(numbers 0-9){ //do something } else if (letters A-Z){ //do something else } 如何在javascript中做到这一点?大多数人都使用 function isNumber(n) { return !isNaN(parseFloat(n)) && isFin

如何定义在文本字段中键入的变量类型?我希望在文本字段中键入一些内容,当您按下搜索按钮时,根据类型,它将显示来自数据库的不同结果

if(numbers 0-9){
   //do something
}  
else if (letters A-Z){
   //do something else
}
如何在javascript中做到这一点?

大多数人都使用

function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}
大多数人都同意

function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}
大多数人都同意

function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}
大多数人都同意

function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

您可以尝试通过执行以下操作将字符串转换为整数:

var a = "3";
var b = +a; // this will try to convert a variable into integer if it can't it will be NaN
你可以检查一下

Boolean(+a) is true then a is Number else it's not a number

您可以尝试通过执行以下操作将字符串转换为整数:

var a = "3";
var b = +a; // this will try to convert a variable into integer if it can't it will be NaN
你可以检查一下

Boolean(+a) is true then a is Number else it's not a number

您可以尝试通过执行以下操作将字符串转换为整数:

var a = "3";
var b = +a; // this will try to convert a variable into integer if it can't it will be NaN
你可以检查一下

Boolean(+a) is true then a is Number else it's not a number

您可以尝试通过执行以下操作将字符串转换为整数:

var a = "3";
var b = +a; // this will try to convert a variable into integer if it can't it will be NaN
你可以检查一下

Boolean(+a) is true then a is Number else it's not a number

您可以尝试Angus Croll在以下内容中定义的方法
toType

实施:

toType({a: 4}); //"object"
toType([1, 2, 3]); //"array"
(function() {console.log(toType(arguments))})(); //arguments
toType(new ReferenceError); //"error"
toType(new Date); //"date"
toType(/a-z/); //"regexp"
toType(Math); //"math"
toType(JSON); //"json"
toType(new Number(4)); //"number"
toType(new String("abc")); //"string"
toType(new Boolean(true)); //"boolean"

您可以尝试Angus Croll在以下内容中定义的方法
toType

实施:

toType({a: 4}); //"object"
toType([1, 2, 3]); //"array"
(function() {console.log(toType(arguments))})(); //arguments
toType(new ReferenceError); //"error"
toType(new Date); //"date"
toType(/a-z/); //"regexp"
toType(Math); //"math"
toType(JSON); //"json"
toType(new Number(4)); //"number"
toType(new String("abc")); //"string"
toType(new Boolean(true)); //"boolean"

您可以尝试Angus Croll在以下内容中定义的方法
toType

实施:

toType({a: 4}); //"object"
toType([1, 2, 3]); //"array"
(function() {console.log(toType(arguments))})(); //arguments
toType(new ReferenceError); //"error"
toType(new Date); //"date"
toType(/a-z/); //"regexp"
toType(Math); //"math"
toType(JSON); //"json"
toType(new Number(4)); //"number"
toType(new String("abc")); //"string"
toType(new Boolean(true)); //"boolean"

您可以尝试Angus Croll在以下内容中定义的方法
toType

实施:

toType({a: 4}); //"object"
toType([1, 2, 3]); //"array"
(function() {console.log(toType(arguments))})(); //arguments
toType(new ReferenceError); //"error"
toType(new Date); //"date"
toType(/a-z/); //"regexp"
toType(Math); //"math"
toType(JSON); //"json"
toType(new Number(4)); //"number"
toType(new String("abc")); //"string"
toType(new Boolean(true)); //"boolean"
如果有数字和字母呢?(即使你不想让它发生,也要做好准备;因为它会发生,即使只是偶然发生。)如果有数字和字母呢?(即使你不想让它发生,也要做好准备;因为它会发生,即使只是偶然发生。)如果有数字和字母呢?(即使你不想让它发生,也要做好准备;因为它会发生,即使只是偶然发生。)如果有数字和字母呢?(即使你不想让这种情况发生,也要做好准备;因为它会发生,即使只是偶然发生。)