jquery Data Type Summary (14) _jquery

Source: Internet
Author: User
Tags commit

In addition to the built-in data types (built-in datatype) in native JS, jquery includes some extended data types (virtual types), such as selectors, events, and so on.

1. String

string is most common and is supported in almost any advanced programming language and scripting language, such as "Hello world!" That is, a string. The string is typed as String. Like what

var typeofstr = typeof "Hello World";//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 Property: Returns the length of a character, such as "hello". Length returns 5

1.3 String Conversion to Boolean:

An empty string ("") defaults to False, and a non-empty string is true (such as "Hello").

2. Number

Number types, such as 3.1415926 or 1, 2, 3 ...

typeof 3.1415926 returns "number".

2.1 Number converts to Boolean:

If a number value is 0, the default is False, otherwise true.

2.2 Because number is implemented with a double-precision floating-point number, the following 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 strings to numbers: Parseint and Parsefloat methods:

parseint ("123") = 123 (decimal conversion)
parseint ("010") = 8 (with octal conversion)
parseint ("0xCAFE") = 51966 (with 16 conversion)
parseint ("010", 10) = 10 (specified with 10 conversion)
parseint ("11", 2) = 3 (specified with binary conversion)
parsefloat ("10.10") = 10.1

3.2 Numbers to Strings

When the number is glued to the (append) string, a string is obtained.
"" + 1 + 2; "12"
"" + (1 + 2); "3"
"+ 0.0000001"; "1e-7"
or use coercion type conversion:
String (1) + string (2); "12"
String (1 + 2); "3"

4. NaN and Infinity

If you call the Parseint method on a non-numeric string, Nan (not a number) is returned, and Nan is commonly used to detect whether a variable is a numeric type, as follows:

isNaN (parseint ("Hello"))//True
Infinity represents infinity or infinitesimal values, such as 1/0//Infinity.

Calling the TypeOf operator on Nan and Infinity returns "Numuber".

In addition Nan==nan returns false, but Infinity==infinity returns TRUE.

5. Integer and Float

They are divided into representations of integers and floating-point types.

6. BOOLEAN

Boolean type, True or false.

7. OBJECT

Everything in JavaScript is object. Returns "Object" for typeof operations on an object.

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

For the Y object above, you can take a dot to get the property value, such as Y.name return "Pete", Y.age return 15

7.1 Array notation (Array access method Access object)

var operations = {Increase: "+ +", Decrease: "--"} 
var operation = "Increase"; 
Operations[operation]//"+ +"; 
operations["multiply"] = "*"; // "*"

Above operations["Multiply"]= "*"; A Key-value pair was added 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 with no attributes or values, default to True

7.4 Object's Prototype property

Dynamically adding objects (functions) to jquery instances with FN (prototype alias) in jquery

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 is added

8. OPTIONS

Almost all jquery plug-ins provide a api,options is a JS object, meaning that the object and its properties are optional (optional). Allow customization.
For example, by submitting a form in AJAX mode,

$ ("#myform"). Ajaxform ()//default takes the Action property value of form as the Ajax-url,method value as the commit type (get/post)
$ ("#myform"). Ajaxform ({url: "mypage.php", type: "POST"});//overrides the URL and commit type submitted to

9. ARRAY

var arr = [1, 2, 3];

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

Reads or sets the value of an element in an array in this way:

var val = arr[0];//val to 1
arr[2] = 4;//now arr The third element is 4

9.1 Array Loop (traversal)

for (var i = 0; i < a.length; i++) {//does something with A[i]}
But when performance is considered, it is best to read the length property only once, as follows:
for (var i = 0, J = A.length; I < J; i++) {//do something with A[i]}
jquery provides each method to traverse an array:
var x = [1, 2, 3]; 
$.each (x, 
function (index, value) { 
console.log ("index", Index, "value", value); 

A 9.2 call to the push method means adding an element to the end of the array, such as X.push (5); and x.[x.length] = 5; Equivalent

9.3 Array other built-in methods:

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 elements of an array, here for the deletion of 2 elements starting from index=1

9.4 Array is an object, so always True

MAP

The map type is used by the AJAX function to hold the data of a request.  This type could is a string, an array<form elements>, and a JQuery object with form elements or an object with Key/value Pairs. In the last case, it's possible to assign multiple values to one key by assigning an array. As below:
{' key[] ': [' Valuea ', ' Valueb ']}

FUNCTION: Anonymous and famous two kinds

11.1 Context, call, and apply

In JavaScript, the variable ' this ' always refers to the current context. 
$ (document). Ready (function () { 
//This refers to window.document}); 
$ ("a"). Click (function () {//This refers to a anchor DOM element
});

SELECTOR

There are lot of plugins that leverage JQuery ' s selectors in the other ways. The validation plugin accepts a selector to specify a dependency, whether an input are required or not:
Emailrules: {required: "#email: Filled"}
This would make a checkbox with name "Emailrules" required only if the user entered an email address in the email field, s Elected via its ID, filtered via a custom selector ": filled" that validation plugin.

EVENT

DOM standard events include: blur, focus, load, resize, scroll, unload, beforeunload, click, DblClick, MouseDown, MouseUp, MouseMove, Mouseov Er, mouseout, MouseEnter, MouseLeave, change, select, Submit, KeyDown, KeyPress, Andkeyup

JQUERY

The jquery object contains a collection of DOM elements. such as $ (' P ') that returns all <p>...</p>
The jquery object behaves like an array and has a length property, or it can access one of the DOM element collections through index. But not an array, there are some methods of the array, such as join ().

Many jquery methods return the jquery object itself, so you can use chained calls:
$ ("P"). CSS ("Color", "red"). Find (". Special"). CSS ("Color", "green");
But if the method you call destroys the jquery object, such as find () and filter (), then the original object is not returned. To return to the original object, you only need to call the end () method again.

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.