Home > Web Front-end > JS Tutorial > body text

jQuery1.6 usage method 1_jquery

WBOY
Release: 2016-05-16 17:59:05
Original
1079 people have browsed it

error: function( msg ) {//Declaration error
throw msg;
},
parseJSON: function( data ) {//Convert the string to json format
if ( typeof data !== "string" || !data ) {//First determine whether it exists and whether it is a string
return null;
}
data = jQuery.trim( data );//Remove the before and after Blank
if ( window.JSON && window.JSON.parse ) {//The advanced version has native JSON conversion function window.JSON
return window.JSON.parse( data );
}
if ( rvalidchars.test( data.replace( rvalidescape, "@" )//
.replace( rvalidtokens, "]" )//
.replace( rvalidbraces, "")) ) {//Perform a simple Test, {true:1},{"a",{}}....all pass
//rvalidchars = /^[],:{}s]*$/,
//rvalidescape = /\(?:["\/bfnrt]|u[0-9a-fA-F]{4})/g,u[0-9a-fA-F]{4} matches Chinese, English and escape characters
//rvalidtokens = /"[^"\nr]*"|true|false|null|-?d (?:.d*)?(?:[eE][ -]?d )?/g ,//The matching string does not contain "", " ", " ”, Boolean value, null, number
//rvalidbraces = /(?:^|:|,)(?:s*[) /g, match (starting with empty or: or,) (followed by zero or Multiple spaces, followed by [) at the end such as [,: [,,[,, [etc.
return (new Function( "return " data ))();
  }
jQuery.error( " Invalid JSON: " data );
},
parseXML: function( data , xml , tmp ) {I don’t understand the use of incoming xml tmp
if ( window.DOMParser ) { // Standard
     / The /DOMParser object parses XML text and returns an XML Document object. To use DOMParser, instantiate it using the constructor without parameters, and then call its //parseFromString() method:
tmp = new DOMParser();
xml = tmp.parseFromString( data , "text/xml" );
} else { // IE
xml = new ActiveXObject( "Microsoft.XMLDOM" );
xml.async = "false ";
xml.loadXML( data );
}
tmp = xml.documentElement;
if ( ! tmp || ! tmp.nodeName || tmp.nodeName === "parsererror" ) {//Determine whether the returned result is empty, not a node, and whether an error is reported
jQuery.error( "Invalid XML: " data );
}
return xml;
}
 globalEval : function( data ) {//Make data executable
if ( data && rnotwhite.test( data ) ) {//Check whether it exists and not empty
( window.execScript || function( data ) {
window[ "eval" ].call( window, data );//window.eval.call(window,data) In some cases, the context cannot be changed in IE, so only Can use window.execScript for IE, other browsers use window.eval.call(window,data);
} )( data );
}
},
nodeName: function( elem, name ) {
return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();//Determine whether it is a node. The node name is uppercase by default. In order to ensure correct judgment, all are converted into the same Format (uppercase)
},
  each: function( object, callback, args ) {
var name, i = 0,
length = object.length,//window,String,Function, Array type is not undefined;..
isObj = length === undefined || jQuery.isFunction( object );//Mainly to distinguish objects and arrays
if ( args ) {//If not passed When entering parameters, the default name and value will be used as parameters. If there are parameters, the passed parameters will be used
if ( isObj ) {
for ( name in object ) {
if ( callback.apply( object[ name ], args ) === false ) {
break;
}
}
} else {
for ( ; i < length; ) {
if ( callback.apply( object[ i ], args ) === false ) {
break;
}
}
}
} else {//If no parameters are passed in,
if ( isObj ) {
for ( name in object ) {// The object[ name ] value is used as the current object, and the name and value are used as parameters
if ( callback.call( object[ name ], name, object[ name ] ) === false ) {//Judge the return value of the callback function and decide whether to continue the loop
break;
}
}
} else {
for ( ; i < length ; ) {//object[ i ] value as the current object, name (i is the order) and value as parameters
if ( callback.call( object[ i ], i, object[ i ] ) === false ) {//Judge the return value of the callback function and decide whether to continue the loop
break;
}
}
}
}
return object;
},
trim: trim ?//Detect whether there is a native trim method, if the parameter text! = intercepts the front and rear blanks, otherwise it returns empty. If there is no native trim, force conversion to a string and then perform regular replacement. Otherwise, an error is reported and regular replacement is used (trimLeft = /^s /,//matches the left blank, trimRight = /s $/,//match right blank),
function( text ) {
return text == null ?
"" :
trim.call( text );
} :
function( text ) {
return text == null ?
"" :
text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
} ,

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!