Table of Contents
There are several types of jquery data types
Home Web Front-end Front-end Q&A How many jquery data types are there?

How many jquery data types are there?

May 18, 2022 am 10:46 AM
jquery

There are 14 jquery data types: 1. String string type; 2. Number type; 3. Math type; 4. NaN non-number and Infinity infinite or infinite small; 5. Integer and Float. Point type; 6. BOOLEAN Boolean type; 7. Array type, etc.

How many jquery data types are there?

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

There are several types of jquery data types

There are 14 types of jquery data types

In addition to the built-in datatypes in native JS, jQuery also includes some Extended data types (virtual types), such as Selectors, Events, etc.

1. String

String is the most common and is supported by almost any high-level programming language and scripting language, such as "Hello world! "That is a string. The type of string is string. For example

var typeOfStr = typeof "hello world";//typeOfStr为“string"
Copy after login

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"]
Copy after login

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 defaults to true (such as "hello").

2. Number

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

typeof 3.1415926 Return is "number"

2.1 Number is converted to Boolean:

If a Number value is 0, the default is 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
Copy after login

3. Math

The following methods are similar to the static methods of the Math class in Java.

Math.PI // 3.141592653589793
Math.cos(Math.PI) // -1
Copy after login

3.1 Convert strings to numbers: parseInt and parseFloat methods:

parseInt("123") = 123 (采用十进制转换)
parseInt("010") = 8 (采用八进制转换)
parseInt("0xCAFE") = 51966 (采用十六进制转换)
parseInt("010", 10) = 10 (指定用10进制转换)
parseInt("11", 2) = 3 (指定用二进制转换)
parseFloat("10.10") = 10.1
Copy after login

3.2 Numbers to strings

When the Number is pasted (append) to the string time, you will get the string.

"" + 1 + 2; // "12"
"" + (1 + 2); // "3"
"" + 0.0000001; // "1e-7"
Copy after login

Or use cast conversion:

String(1) + String(2); //"12"
String(1 + 2); //"3"
Copy after login

4. NaN and Infinity

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

isNaN(parseInt("hello", 10)) // true
Copy after login

Infinity means that the value is infinitely large or infinitely small, 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

are divided into integer and floating point types.

6. BOOLEAN

Boolean type, true or false.

7. OBJECT

Everything in JavaScript is an object. Performing a typeof operation on an object returns "object".

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

For the above y object, you can use dots to obtain attribute values. For example, y.name returns "Pete", y.age returns 15

7.1 Array Notation (array access method to access the object )

var operations = { increase: "++", decrease: "--" } 
var operation = "increase"; 
operations[operation] // "++"; 
operations["multiply"] = "*"; // "*"
Copy after login

The above operations["multiply"]="*"; adds a key-value pair to the operations object.

7.2 Object iteration access: for-in

var obj = { name: "Pete", age: 15}; 
for(key in obj) { 
alert("key is "+[key]+", value is "+obj[key]); 
}
Copy after login

7.3 Any object, regardless of whether it has attributes and values, defaults to true

7.4 Prototype attribute of the object

Use fn (alias of Prototype) 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
Copy after login

8. OPTIONS

Almost all jQuery plug-ins provide an API based on OPTIONS. OPTIONS is a JS object, which means that the object and its properties are optional. Allow customization.

For example, if you submit a form using Ajax,

$("#myform").ajaxForm();//默认采用Form的Action属性值作为Ajax-URL,Method值作为提交类型(GET/POST)
$("#myform").ajaxForm({ url: "mypage.php", type: "POST" });//则覆盖了提交到的URL和提交类型
Copy after login

9. ARRAY

var arr = [1, 2, 3];
Copy after login

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

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

var val = arr[0];//val为1
arr[2] = 4;//现在arr第三个元素为4
Copy after login

9.1 Array loop (traversal)

for (var i = 0; i < a.length; i++) { // Do something with a[i] }
Copy after login

But when considering performance, it is best Read the length property only once, as follows:

for (var i = 0, j = a.length; i < j; i++) { // Do something with a[i] }
Copy after login

jQuery provides the each method to traverse the array:

var x = [1, 2, 3]; 
$.each(x, 
function(index, value) { 
console.log("index", index, "value", value); 
});
Copy after login

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

9.3 Other built-in methods of 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) // 用于插入、删除或替换数组元素,这里为删除从index=1开始的2个元素
Copy after login

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

, 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 window.document}); 
$("a").click(function() { // this refers to an anchor DOM element
});
Copy after login

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标准事件包括:blur, focus, load, resize, scroll, unload, beforeunload, click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, mouseenter, mouseleave, change, select, submit, keydown, keypress, andkeyup

14. JQUERY

JQUERY对象包含DOM元素的集合。比如$('p')即返回所有

...

JQUERY对象行为类似数组,也有length属性,也可以通过index访问DOM元素集合中的某个。但是不是数组,不具备数组的某些方法,比如join()。

许多jQuery方法返回jQuery对象本身,所以可以采用链式调用:

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

但是如果你调用的方法会破坏jQuery对象,比如find()和filter(),则返回的不是原对象。要返回到原对象只需要再调用end()方法即可。

相关视频教程推荐:jQuery视频教程

The above is the detailed content of How many jquery data types are there?. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of jQuery reference methods: Quick start guide Detailed explanation of jQuery reference methods: Quick start guide Feb 27, 2024 pm 06:45 PM

Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

In-depth analysis: jQuery's advantages and disadvantages In-depth analysis: jQuery's advantages and disadvantages Feb 27, 2024 pm 05:18 PM

jQuery is a fast, small, feature-rich JavaScript library widely used in front-end development. Since its release in 2006, jQuery has become one of the tools of choice for many developers, but in practical applications, it also has some advantages and disadvantages. This article will deeply analyze the advantages and disadvantages of jQuery and illustrate it with specific code examples. Advantages: 1. Concise syntax jQuery's syntax design is concise and clear, which can greatly improve the readability and writing efficiency of the code. for example,

How to remove the height attribute of an element with jQuery? How to remove the height attribute of an element with jQuery? Feb 28, 2024 am 08:39 AM

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: &lt

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on ​​the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to tell if a jQuery element has a specific attribute? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

Understand the role and application scenarios of eq in jQuery Understand the role and application scenarios of eq in jQuery Feb 28, 2024 pm 01:15 PM

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

See all articles