JQuery data type summary, jquery Data Type

Source: Internet
Author: User

JQuery data type summary, jquery Data Type

In addition to built-in data types (built-in datatype) in native JS, jQuery also includes some extended data types (such as Selectors and Events.

 

1. String

String is the most common. It is supported in almost any advanced programming language or scripting language, such as "Hello world! "Is a string. The string type is string. For example

Var typeOfStr = typeof "hello world"; // The value of typeOfStr is "string"

1.1 String built-in method

"Hello". charAt (0) // "h"

"Hello". toUpperCase () // "HELLO"

"Hello". toLowerCase () // "hello"

"Hello". replace (/e | o/g, "x") // "hxllx"

"1, 2, 3". split (",") // ["1", "2", "3"]

1.2 length attribute: returns the length of a character. For example, "hello". length returns 5.

1.3 convert a string to Boolean:

The default value of an empty string ("") is false, whereas that of a non-empty string is true (for example, "hello ").

 

2. Number

Numeric type, such as 3.1415926 or 1, 2, 3...

Typeof 3.1415926 returns "number"

2.1 Number to Boolean:

If the value of a Number is 0, the default value is false; otherwise, the value is true.

2.2 because the Number is implemented using a double-precision floating point Number, the following situation is reasonable:

0.1 + 0.2 // 0.30000000000000004

 

3. Math

The following method is similar to the static method of the Math class in Java.

Math.pi // 3.141592653589793

Math. cos (Math. PI) //-1

3.1 convert the string into numbers: parseInt and parseFloat methods:

ParseInt ("123") = 123 (decimal conversion)

ParseInt ("010") = 8 (octal conversion)

ParseInt ("0 xCAFE") = 51966 (hexadecimal conversion)

ParseInt ("010", 10) = 10 (10 hexadecimal conversion is specified)

ParseInt ("11", 2) = 3 (specify binary conversion)

ParseFloat ("10.10") = 10.1

3.2 numeric to string

When the Number is attached to the (append) string, the string is obtained.

"" + 1 + 2; // "12"

"" + (1 + 2); // "3"

"& Quot; + 0.0000001; // & quot; 1e-7 & quot"

Or use force type conversion:

String (1) + String (2); // "12"

String (1 + 2); // "3"

 

4. NaN and Infinity

If the parseInt method is called for a non-numeric string, NaN (Not a Number) is returned. NaN is often used to detect whether a variable is of the numeric type, as follows:

IsNaN (parseInt ("hello", 10) // true

Infinity indicates that the value is infinite or infinitely small, for example, 1/0 // Infinity.

If both NaN and Infinity call the typeof operator, "numuber" is returned ".

In addition, NaN = NaN returns false, but Infinity = Infinity returns true.

 

5. Integer and Float

It can be an integer or floating point type.

Http://www.cnblogs.com/roucheng/

6. BOOLEAN

Boolean, true, or false.

 

7. OBJECT

Everything in JavaScript is an object. If a typeof operation is performed on an object, "object" is returned ".

Var x = {};

Var y = {name: "Pete", age: 15 };

For the above y object, the property value can be obtained using dots. For example, if y. name returns "Pete", y. age returns 15

7.1 Array Notation (accessing objects through Array access)

Var operations = {increase: "++", decrease :"--"}

Var operation = "increase ";

Operations [operation] // "++ ";

Operations ["multiply"] = "*";//"*"

Operations ["multiply"] = "*"; added a key-value pair to the operations object.

7.2 object circular access: for-in

Var obj = {name: "Pete", age: 15 };

For (key in obj ){

Alert ("key is" + [key] + ", value is" + obj [key]);

}

7.3 any object, regardless of its attributes and values, is set to true by default.

7.4 Prototype attribute of the object

Using fn (Prototype alias) in jQuery to dynamically add objects (functions) to jQuery Instances)

Var form = $ ("# myform ");

Form. clearForm; // undefined

Form. fn. clearForm = function (){

Return this. find (": input"). each (function () {this. value = "" ;}). end ();

};

Form. clearForm () // works for all instances of jQuery objects, because the new method was added

 

8. OPTIONS

Almost all jQuery plug-ins provide an OPTIONS-based API. OPTIONS is a JS object, meaning that the object and its attributes are optional (optional ). Customization is allowed.

For example, submitting a form using Ajax,

$ ("# Myform"). ajaxForm (); // by default, the Action attribute value of Form is used as Ajax-URL, and the Method value is used as the submission type (GET/POST)

$ ("# Myform"). ajaxForm ({url: "mypage. php", type: "POST"}); // overwrites the submitted URL and submission type

 

9. ARRAY

Var arr = [1, 2, 3];

ARRAY is a variable lists. ARRAY is also an object.

Read or set the value of the element in ARRAY in this way:

Var val = arr [0]; // val is 1

Arr [2] = 4; // currently, the third element of arr is 4.

9.1 array loop (traversal)

For (var I = 0; I <a. length; I ++) {// Do something with a [I]}

However, when considering performance, it is best to read the length attribute only once, as shown below:

For (var I = 0, j = a. length; I <j; I ++) {// Do something with a [I]}

JQuery provides the each method to traverse Arrays:

Var x = [1, 2, 3];

$. Each (x,

Function (index, value ){

Console. log ("index", index, "value", value );

});

9.2 calling the push method on the array means adding an element to the end of the array, such as x. push (5); equivalent to x. [x. length] = 5;

9.3 other built-in methods for Arrays:

Var x = [0, 3, 1, 2];

X. reverse () // [2, 1, 3, 0]

X. join ("-") // "2-1-3-0"

X. pop () // [2, 1, 3]

X. unshift (-1) // [-1, 2, 1, 3]

X. shift () // [2, 1, 3]

X. sort () // [1, 2, 3]

X. splice (1, 2) // used to insert, delete, or replace array elements. Here we delete the two elements starting from index = 1.

9.4 The array is an object, so it is always true.

 

10. MAP

The map type is used by the AJAX function to hold the data of a request. this type cocould be a string, an array <form elements>, a jQuery object with form elements or an object with key/value pairs. in the last case, it is possible to assign multiple values to one key by assigning an array. as below:

{'Key [] ': ['valuea', 'valueb ']}

 

11. FUNCTION: anonymous and named

11.1 Context, Call, and Apply

In JavaScript, the variable "this" always refers to the current context.

$ (Document). ready (function (){

// This refers to upload your doc ument });

$ ("A"). click (function () {// this refers to an anchor DOM element

});

 

12. SELECTOR

There are lot of plugins that leverage jQuery's selectors in other ways. The validation plugin accepts a selector to specify a dependency, whether an input is required or not:

Emailrules: {required: "# email: filled "}

This wocould make a checkbox with name "emailrules" required only if the user entered an email address in the email field, selected via its id, filtered via a custom selector ": filled "that the validation plugin provides.

 

13. EVENT

DOM standard events include: blur, focus, load, resize, scroll, unload, beforeunload, click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, mouseenter, mouseleave, change, select, submit, keydown, keypress, andkeyup

 

14. JQUERY

A collection of DOM elements in a JQUERY object. For example, $ ('P') returns all <p>... </p>

The JQUERY object acts like an array and also has the length attribute. You can also access a specific DOM Element Set Through index. But it is not an array and does not have some methods of arrays, such as join ().

Many jQuery Methods return the jQuery object itself, so you can use the chain call:

$ ("P" ).css ("color", "red"). find (". special" ).css ("color", "green ");

However, if the method you call destroys jQuery objects, such as find () and filter (), the returned result is not the original object. To return to the original object, you only need to call the end () method.

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.