zoukankan      html  css  js  c++  java
  • 验证输入的是数字,小数

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>	
    <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
    </head>
    <body>
    
    <script>
    $(function () { 
    	function fun( html ){ 
    		document.body.innerHTML += "<br>" + html; 
    	} 
    	// true
    	fun($.isNumeric( "-10" ));  
    	fun($.isNumeric( "0" ));
    	fun($.isNumeric( 0xFF ));
    	fun($.isNumeric( "0xFF" ));
    	fun($.isNumeric( "8e5" ));
    	fun($.isNumeric( "3.1415" ));
    	fun($.isNumeric( +10 ));
    	fun($.isNumeric( 0144  ));
    	//false
    	fun($.isNumeric( "-0x42" ));  
    	fun($.isNumeric( "7.2acdgs" ));
    	fun($.isNumeric( "" ));
    	fun($.isNumeric( {} ));
    	fun($.isNumeric( NaN ));
    	fun($.isNumeric( null ));
    	fun($.isNumeric( true ));
    	fun($.isNumeric( Infinity  ));
    	fun($.isNumeric( undefined  ));	
    })
    </script>
     
    </body>
    </html>

    定义和用法

    $.isNumeric() 函数用于判断指定参数是否是一个数字值。

    注意:在jQuery 3.0中,$.isNumeric()方法只有接收number类型的参数,或者是可以被强制为有限数值的 string类型的参数时,才会返回true,否则返回false。


    语法

    $.isNumeric( value )

    参数 描述
    value 任意类型 需要进行判断的任意值。

  • 相关阅读:
    Gulp使用入门操作---压缩JS
    Linux如何查看进程及如何杀死进程
    连不上GitHub,也ping不通,亲测解决方案
    idea一键生成mybatis工具
    idea逆向生成hibernate工程
    idea常用快捷键大全
    mysql日期函数
    数据库事务
    idea激活码
    oracle创建表前校验是否存在
  • 原文地址:https://www.cnblogs.com/MartinLee/p/7622517.html
Copyright © 2011-2022 走看看