In addition to containing built-in datatypes in native JS, jQuery also includes some extended data types, such as Selectors, Events, etc.
1. String
String is the most common and is supported in almost any high-level programming language and scripting language, such as "Hello world!", that is, strings. The type of string is string. for example
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 attribute: Returns the character length, such as "hello".length returns 5
1.3 Convert string to Boolean:
An empty string ("") defaults to false, while 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 converted to Boolean:
If a Number value is 0, it defaults to false, otherwise it is true.
2.2 Since Number is implemented using double-precision floating point numbers, 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.
// 3.141592653589793
() // -1
3.1 Stringing a string into a number: parseInt and parseFloat methods:
parseInt("123") = 123 (converted in decimal)
parseInt("010") = 8 (using octal conversion)
parseInt("0xCAFE") = 51966 (in hexadecimal conversion)
parseInt("010", 10) = 10 (Specify the conversion in decimal)
parseInt("11", 2) = 3 (Specify binary conversion)
parseFloat("10.10") = 10.1
3.2 Number to string
When you paste Number into (append) the string, you will get the string.
"" + 1 + 2; // "12"
"" + (1 + 2); // "3"
"" + 0.0000001; // "1e-7"
Or cast:
String(1) + String(2); //"12"
String(1 + 2); //"3"
4. NaN and Infinity
If the parseInt method is called on a non-numeric string, NaN will be returned (Not a Number). NaN is often used to detect whether a variable is of a numeric type, as follows:
isNaN(parseInt("hello", 10)) // true
Infinity means that the value is infinite or infinitely small, such as 1/0 // Infinity.
Calling the typeof operators to both NaN and Infinity returns "numuber".
In addition, NaN==NaN returns false, but Infinity==Infinity returns true.
5. Integer and Float
It is divided into integer and floating point.
6. BOOLEAN
Boolean type, true or false.
7. OBJECT
Everything in JavaScript is an object. Return "object" when performing typeof operation on an object.
var x = {}; var y = { name: "Pete", age: 15 };
For the above y object, you can use dots to get the attribute value, such as returning "Pete" and returning 15
7.1 Array Notation (array access method to access objects)
var operations = { increase: "++", decrease: "--" } var operation = "increase"; operations[operation] // "++"; operations["multiply"] = "*"; // "*"
The above operations["multiply"]="*"; adds a key-value pair to the operations object.
7.2 Object idling: for-in
var obj = { name: "Pete", age: 15}; for(key in obj) { alert("key is "+[key]+", value is "+obj[key]); }
7.3 Any object has or does not have attributes or values, defaults to true.
7.4 Prototype properties of an object
Use fn (alias for Prototype) to dynamically add objects (functions) to jQuery Instances in jQuery
var form = $("#myform"); ; // undefined = function() { return (":input").each(function() { = ""; }).end(); }; () // works for all instances of jQuery objects, because the new method was added
8. OPTIONS
Almost all jQuery plugins provide an OPTIONS-based API, which is a JS object, meaning that the object and its properties are optional (optional). Allow customization.
For example, submit a form using Ajax method.
$("#myform").ajaxForm();//By default, Form's Action property value is used as Ajax-URL, and Method value is used as the commit type (GET/POST)
$("#myform").ajaxForm({ url: "", type: "POST" });//Then overwrites the URL and commit type
9. ARRAY
var arr = [1, 2, 3];
ARRAY is variable lists. ARRAY is also an object.
Read or set the value of an element in ARRAY in this way:
var val = arr[0];//val is 1arr[2] = 4;//NowarrThe third element is4
9.1 Array Loop (Traveling)
for (var i = 0; i < ; i++) { // Do something with a[i] } But when performance is considered,It is better to read it only oncelengthproperty,as follows: for (var i = 0, j = ; i < j; i++) { // Do something with a[i] } jQueryProvidedeachMethod traverse array: var x = [1, 2, 3]; $.each(x, function(index, value) { ("index", index, "value", value); });
9.2 Calling the push method on an array means adding an element to the end of the array, such as (5); and x.[] = 5; equivalent
9.3 Other built-in methods for arrays:
var x = [0, 3, 1, 2]; () // [2, 1, 3, 0] (" – ") // "2 - 1 - 3 - 0" () // [2, 1, 3] (-1) // [-1, 2, 1, 3] () // [2, 1, 3] () // [1, 2, 3] (1, 2) // For insertion、Delete or replace array elements,Here is the delete fromindex=1Beginning2Elements
9.4 Arrays are objects, so they are always true
10. MAP
The map type is used by the AJAX function to hold the data of a request. This type could 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 famous
11.1 Context, Call and Apply
In JavaScript, the variable "this" always refers to the current context. $(document).ready(function() { // this refers to }); $("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 would 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 JQUERY object contains a collection of DOM elements. For example, $('p') returns all <p>...</p>
JQUERY objects behave like arrays, have length attributes, and can also access a certain DOM element collection 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 chain calls:
$("p").css("color", "red").find(".special").css("color", "green");
But if the method you call will destroy the jQuery object, such as find() and filter(), the returned object is not the original object. To return to the original object, you only need to call the end() method.