Home >Web Front-end >JS Tutorial >jquery method to determine whether it is a number

jquery method to determine whether it is a number

藏色散人
藏色散人Original
2020-11-26 11:20:072199browse

The jquery method to determine whether it is a number: first create a front-end code sample file; then use the "if(!isNaN(t)){...}" method to determine whether it is a number; finally output the judgment result: Can.

jquery method to determine whether it is a number

The operating environment of this tutorial: Windows 7 system, jquery version 1.10.0. This method is suitable for all brands of computers.

Recommended: "jquery Tutorial"

jQuery method to determine whether it is a number and convert number function

<script language="javascript">
var t=$("#id").val();//这个就是我们要判断的值了
if(!isNaN(t)){
  alert("是数字");
}else{
  alert("不全是数字");
}
</script>

Attachment:

JavaScript Number() function

Number() function converts the value of the object into a number.

<script type="text/javascript">
var test1= new Boolean(true);
var test2= new Boolean(false);
var test3= new Date();
var test4= new String("999");
var test5= new String("999 888");
document.write(Number(test1)+ "<br />");
document.write(Number(test2)+ "<br />");
document.write(Number(test3)+ "<br />");
document.write(Number(test4)+ "<br />");
document.write(Number(test5)+ "<br />");
</script>

Output

1
0
1256657776588
999
NaN

For more programming-related knowledge, please visit: Programming Learning! !

The above is the detailed content of jquery method to determine whether it is a number. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn