jquery tool method.(1) $.isnumeric (obj) This method determines whether an incoming object is a number or can be converted to a number.IsNumeric:
function(obj) { //parsefloat NaNs Numeric-cast false positives (null|true|false| "") //... but misinterprets leading-number strings, particularly hex literals ("0x ...") //Subtraction forces infinities to NaN
return obj-parsefloat (obj) >= 0; },use the '-' to convert obj to a number first, because if the passed-in string contains non-numeric characters, then obj will be converted to Nan,isnumeric to return false.Alert ( ' 55a ' -0)//nanNote: The native method of JS parsefloat the conversion error when processing a 16 binary string, he will take the 16 binary flag 0x 0 ....
var f = parsefloat ( ' 0xAAAA ', 2);alert (f); //0
Test_script
var obj = {toString:
function(){
return ' 6 ';}};
var f = $.isnumeric (obj); alert (f);//true
(2) isplainobject (obj)This method determines whether the incoming object is a ' pure ' object, that is, the object created with the literal {}, or new object.Test_script
functionPerson (name, age) {
This . Name = name;
This . Age = age; };
var p = $.isplainobject (
New Person ()); alert (p);//false Alert ($.isplainobject ({}));//true alert ($.isplainobject (document.getElementById (' Div1 ')));//false
isplainobject (obj) source codeIsplainobject:
function(obj) { //Not object or DOM element or window returns false
if (Jquery.type (obj)!== "Object" | | | obj.nodetype | | jquery.iswindow (OBJ)) {
return
false; }
//support:
Firefox <20 //The Try/catch suppresses exceptions thrown when attempting to access //The "constructor" property of certain host objects,
ie. |window.location| //https://bugzilla.mozilla.org/show_bug.cgi?id=814622
Try { //is a custom object that returns False //The custom object is judged by the custom object if the isPrototypeOf method is inherited from the prototype object of {}
if (obj.constructor && !hasown.call (Obj.constructor.prototype,"isPrototypeOf" ) ) {
return
false; } }
Catch (e) {
return
false; }
//If the function hasn ' t returned already, we ' re confident that // |
obj | is a plain object, created by {} or constructed with new object
return
true; },