贴上jQuery的源码 isNumeric: function( obj ) { // As of jQuery 3.0, isNumeric is limited to // strings and numbers (primitives or objects) // that can be coerced to finite numbers (gh-2662) var type = jQuery.type( obj ); return ( type === "number" || type === "string" ) && // parseFloat NaNs numeric-cast false positives ("") // ...but misinterprets leading-number strings, particularly hex literals ("0x...") // subtraction forces infinities to NaN !isNaN( obj - parseFloat( obj ) ); },为什么需要obj - parseFloat( obj )而不是直接obj - obj是为了排除什么情况?在问题补充回答。空字符串的情况
1 回答
互换的青春
TA贡献1797条经验 获得超6个赞
// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
注释里已经写的很明白了啊
添加回答
举报
0/150
提交
取消