Possible Duplicate:
Is there a (built-in) way in JavaScript to check if a string is a valid number?
我在 riak map 缩减作业中使用 JS。我有一个想要映射的号码,并且需要是一个号码。
如果我有一个变量:
var wp=sfggz5341&& or var=100
如何测试 if 数字?
例如
if wp==Number:
OK
else:
pass
最佳答案
您可以使用 typeof
运算符(有关详细信息,请参阅 MDN):
var wp = "sfggz53141";
if (typeof wp === "number") {
// number here
} else if (typeof wp === "string") {
// string here
}
关于javascript 和测试数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14495426/