Agri-net 1558 Agri-net

Source: Internet
Author: User
Tags number strings

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;       },

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.