为什么$ .isnumeric为false

用户名

我正在编写一些JavaScript,并且有一个表需要在其中测试数据库密钥(数字)或默认值(“ NO MATCH”)的字段。我正在尝试使用jQuery函数'isNumeric'

代码是:

var id = $('#myDataTable input:checked').map(function(){
     return $(this).closest('tr').find('td:eq(3)').text();
}).get();

console.log(" ID "+id);
console.log(" ID2 "+$.isNumeric(id));

在控制台中,我看到:

ID 1
ID2 false

为什么这不是真的?

i

.get()返回["1"]非数字数组

当您将其登录到控制台时,您看不到该内容,因为您将其与字符串连接["1"].toString()"1"

相反,在调试时,最好避免将变量强制转换为其他类型。console.log("ID", id)会更好。

要获取字符串而不是数组,可以使用.get(0)[0]

但是,如果您只对第一个字符串感兴趣,则没有必要使用map

var id = $('#myDataTable input:checked').eq(0)
         .closest('tr').find('td').eq(3)
         .text();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么''↊'.isnumeric()`为假?

当输入为“ ???”时,StringUtils isNumeric返回true,为什么?

为什么{} == false评估为false,而[] == false评估为true?

为什么“ False is False is False”评估为“ True”?

为什么“ False is False is False”评估为“ True”?

为什么“ True == False is False”评估为False?

为什么isDrawerVisible总是显示为false

为什么“ []是[]”在python中评估为False

为什么JavaScript JSON评估为false?

为什么`1> undefined`评估为false?

为什么$ false -eq“”为true?

为什么将if条件设置为!false?

为什么输出为0(= false)?

为什么在Javascript中,(!+ [] + [])为'true'和(false + [])为'false'?

为什么在Python中'[] == False'的答案为False?

为什么 (true || false && false) 评估为 true?

为什么print('a'>'b')为false,而print('a'>'A')为True?

为什么hasNext()为False,而hasNextLine()为True?

为什么'0为假,但'False为真?

为什么false ==“ false”是false?

为什么{} == {}等于false?

为什么“ a”>“ A”为真?

为什么Symfony NotNull约束抛出错误为false?

为什么我在Python中的if语句评估为False?

为什么“ true” == true在JavaScript中显示为false?

为什么Object.prototype instanceof Object为false?

即使verifyHostname为false,为什么还要进行主机验证?

为什么(1 == 2!= 3)在Python中评估为False?

为什么null不in(1,2,3)为false