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 任意类型 需要进行判断的任意值。

  • 相关阅读:
    mysql中文乱码
    阻止保存要求重新创建表的更改
    PowerDesigner连接数据库(Oracle)
    PowerDesigner连接数据库(SqlServer)
    Environment Variable: "PATH" 失败
    pl/sql查看锁表及解锁
    Oracle将误闪的数据认回到指定的时间段
    内存监测2
    Windows常用的一些DOC命令
    何为序列化
  • 原文地址:https://www.cnblogs.com/MartinLee/p/7622517.html
Copyright © 2011-2022 走看看