search
HomeWeb Front-endFront-end Q&AHow many jquery data types are there?

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"

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

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

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

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"

Or use cast conversion:

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

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

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 };

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"] = "*"; // "*"

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]); 
}

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

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和提交类型

9. ARRAY

var arr = [1, 2, 3];

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

9.1 Array loop (traversal)

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

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] }

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); 
});

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个元素

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
});

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
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
Frontend Development with React: Advantages and TechniquesFrontend Development with React: Advantages and TechniquesApr 17, 2025 am 12:25 AM

The advantages of React are its flexibility and efficiency, which are reflected in: 1) Component-based design improves code reusability; 2) Virtual DOM technology optimizes performance, especially when handling large amounts of data updates; 3) The rich ecosystem provides a large number of third-party libraries and tools. By understanding how React works and uses examples, you can master its core concepts and best practices to build an efficient, maintainable user interface.

React vs. Other Frameworks: Comparing and Contrasting OptionsReact vs. Other Frameworks: Comparing and Contrasting OptionsApr 17, 2025 am 12:23 AM

React is a JavaScript library for building user interfaces, suitable for large and complex applications. 1. The core of React is componentization and virtual DOM, which improves UI rendering performance. 2. Compared with Vue, React is more flexible but has a steep learning curve, which is suitable for large projects. 3. Compared with Angular, React is lighter, dependent on the community ecology, and suitable for projects that require flexibility.

Demystifying React in HTML: How It All WorksDemystifying React in HTML: How It All WorksApr 17, 2025 am 12:21 AM

React operates in HTML via virtual DOM. 1) React uses JSX syntax to write HTML-like structures. 2) Virtual DOM management UI update, efficient rendering through Diffing algorithm. 3) Use ReactDOM.render() to render the component to the real DOM. 4) Optimization and best practices include using React.memo and component splitting to improve performance and maintainability.

React in Action: Examples of Real-World ApplicationsReact in Action: Examples of Real-World ApplicationsApr 17, 2025 am 12:20 AM

React is widely used in e-commerce, social media and data visualization. 1) E-commerce platforms use React to build shopping cart components, use useState to manage state, onClick to process events, and map function to render lists. 2) Social media applications interact with the API through useEffect to display dynamic content. 3) Data visualization uses react-chartjs-2 library to render charts, and component design is easy to embed applications.

Frontend Architecture with React: Best PracticesFrontend Architecture with React: Best PracticesApr 17, 2025 am 12:10 AM

Best practices for React front-end architecture include: 1. Component design and reuse: design a single responsibility, easy to understand and test components to achieve high reuse. 2. State management: Use useState, useReducer, ContextAPI or Redux/MobX to manage state to avoid excessive complexity. 3. Performance optimization: Optimize performance through React.memo, useCallback, useMemo and other methods to find the balance point. 4. Code organization and modularity: Organize code according to functional modules to improve manageability and maintainability. 5. Testing and Quality Assurance: Testing with Jest and ReactTestingLibrary to ensure the quality and reliability of the code

React Inside HTML: Integrating JavaScript for Dynamic Web PagesReact Inside HTML: Integrating JavaScript for Dynamic Web PagesApr 16, 2025 am 12:06 AM

To integrate React into HTML, follow these steps: 1. Introduce React and ReactDOM in HTML files. 2. Define a React component. 3. Render the component into HTML elements using ReactDOM. Through these steps, static HTML pages can be transformed into dynamic, interactive experiences.

The Benefits of React: Performance, Reusability, and MoreThe Benefits of React: Performance, Reusability, and MoreApr 15, 2025 am 12:05 AM

React’s popularity includes its performance optimization, component reuse and a rich ecosystem. 1. Performance optimization achieves efficient updates through virtual DOM and diffing mechanisms. 2. Component Reuse Reduces duplicate code by reusable components. 3. Rich ecosystem and one-way data flow enhance the development experience.

React: Creating Dynamic and Interactive User InterfacesReact: Creating Dynamic and Interactive User InterfacesApr 14, 2025 am 12:08 AM

React is the tool of choice for building dynamic and interactive user interfaces. 1) Componentization and JSX make UI splitting and reusing simple. 2) State management is implemented through the useState hook to trigger UI updates. 3) The event processing mechanism responds to user interaction and improves user experience.

See all articles

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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools