JQuery .isNumeric

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8343348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 10:23:38  来源:igfitidea点击:

JQuery .isNumeric

jquery

提问by Nate Pet

I have a text box with an id of EmpNum. I cannot figure out how to use jQuery's isNumeric to check to see if the value is numeric or not.

我有一个 ID 为 EmpNum 的文本框。我无法弄清楚如何使用 jQuery 的 isNumeric 来检查该值是否为数字。

I tried:

我试过:

    ('#.EmpNum').IsNumeric 

but that did not work.

但这没有用。

回答by Ya Zhuang

according to http://api.jquery.com/jQuery.isNumeric/

根据http://api.jquery.com/jQuery.isNumeric/

it's :jQuery.isNumeric(value)

它的 :jQuery.isNumeric(value)

so, it should be $.isNumeric($("#EmpNum").val())

所以,应该是 $.isNumeric($("#EmpNum").val())

回答by Laurence Burke

Shouldn't it be more like...

不应该更像...

if($.isNumeric($('#EmpNum').val()))

回答by aziz punjani

Pass in the value as an argument to isNumeric. Also make sure you are using jQuery version 1.7 as this was added in 1.7.

将值作为参数传递给 isNumeric。还要确保您使用的是 jQuery 1.7 版,因为这是在 1.7 中添加的。

$.isNumeric( $('#EmpNum').val() )

回答by homi

it should be like this

应该是这样的

$.isNumeric($('#EmpNum').val());

回答by gaurav gupta

You Should use simple and easy way like:

您应该使用简单易行的方法,例如:

var value=$('#txtNumber').val();

var value=$('#txtNumber').val();

if($.isNumeric(value))

if($.isNumeric(value))

{

{

//write your code here

//在这里写你的代码

}

}

回答by IVIike

Depending on what version of jQuery you are using, but as "$.isNumeric()" function is deprecated (https://jquery.com/upgrade-guide/3.0/#breaking-change-jquery-isnumeric-and-custom-tostring) since jQuery Core 3.0 Update, I found a custom solution for this problem (originally posted here: https://stackoverflow.com/a/9716488/3323790):

取决于您使用的 jQuery 版本,但不推荐使用“$.isNumeric()”函数(https://jquery.com/upgrade-guide/3.0/#break-change-jquery-isnumeric-and-custom- tostring)自 jQuery Core 3.0 更新以来,我找到了针对此问题的自定义解决方案(最初发布在这里:https: //stackoverflow.com/a/9716488/3323790):

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

回答by Rich O'Kelly

Try the following:

请尝试以下操作:

$.isNumeric($('#EmpNum').text())

Also the isNumeric methodwas only added in version 1.7, which version are you using?

此外,isNumeric 方法仅在 1.7 版中添加,您使用的是哪个版本?

See here for jsFiddle.

有关 jsFiddle,请参见此处。

回答by Justin Lachapelle

For me $.isNumeric($('#EmpNum').val());did not work.

对我来说$.isNumeric($('#EmpNum').val());没有用。

I had to use this:

我不得不使用这个:

var temp = $('#EmpNum').val();

$.isNumeric(temp);