Home Web Front-end JS Tutorial jQuery study notes Manipulating jQuery objects Attribute processing_jquery

jQuery study notes Manipulating jQuery objects Attribute processing_jquery

May 16, 2016 pm 05:49 PM

Attribute processing of elements

方法

描述

attr(name)

attr(name,value)

attr(name,fn(index,value))

attr({name1:value1,…,nameN:valueN})

获取某个属性的取值,或可以用于设置某个属性的值。还可以使用函数作为参数,将函数返回值作为需要为元素属性设置的值,比如将第(index 1)个元素的name属性设置为函数返回值(实际上,明白函数式就根本不需要这说明)。也可以一次性给同一元素多个属性

removeAttr(name)

删除某个元素的属性取值

Method

Description

方法

描述

attr(“class”)

removeAttr(“class”)

class明显也是属性,所以attr()完全可以处理

addClass(value)

为元素的class属性追加一个或多个属性值。多个属性值,值与值之间同样用空格连接

removeClass(value)

为元素的class属性移除一个或多个属性值

toggleClass(value)

控制class属性中一个或多个属性值的切换,即存在就删除,不存在则添加

hasClass(value)

判断元素class属性中是否含有某个属性值,返回布尔值

attr(name)

attr(name,value)

attr(name,fn(index,value))

方法

描述

html()

html(value)

html(fn(index,value))

获取元素内部的HTML代码,也可以设置元素内部的HTML代码。还可以使用函数参数,把返回值作为需要在元素内部添加的HTML代码

text()

text(value)

text(fn(index,value))

获取元素内部的文本内容,也可以设置元素内部的文本内容,但是该方法不但替换原有文本内容,连后代元素一并替换。还可以使用函数参数,把返回值作为需要在元素内部添加的文本内容

attr({name1:value1,…,nameN:valueN})

方法

描述

val()

val(value)

val(fn(index,value))

val([value1,…, valueN])

获取表单元素的value属性的值,或可以设置表单元素的value属性的值。也可以用函数参数。还可以选定具有特定value属性值的表单选项,对于radio和未设置mutiple的select元素,val参数中只有最后一个value值有效

Get the value of an attribute, or can be used to set the value of an attribute. You can also use a function as a parameter and use the function return value as the value that needs to be set for the element attribute. For example, set the name attribute of the (index 1) element to the function return value (in fact, if you understand the functional expression, you don’t need this explanation at all. ). You can also give multiple attributes to the same element at once
removeAttr(name) Delete the attribute value of an element
element’s class attribute processing
Method Description
attr(“class”) removeAttr(“class”) Class is obviously an attribute, so attr() can completely handle it
addClass(value) Append one or more attribute values ​​to the element's class attribute. Multiple attribute values, the values ​​are also connected with spaces
removeClass(value) Remove one or more attribute values ​​from the element's class attribute
toggleClass(value) Control the switching of one or more attribute values ​​​​in the class attribute, that is, delete it if it exists, and add it if it does not exist
hasClass(value) Determine whether the element's class attribute contains a certain attribute value and return a Boolean value
HTML and text processing inside the element
Method Description
html() html(value) html(fn(index,value)) Get the HTML code inside the element, and you can also set the HTML code inside the element. You can also use function parameters and use the return value as the HTML code that needs to be added inside the element
text() text(value) text(fn(index,value)) Get the text content inside the element, and you can also set the text content inside the element. However, this method not only replaces the original text content, but also replaces the descendant elements. You can also use function parameters and use the return value as the text content that needs to be added inside the element
Attribute processing of form elements
Method Description
val() val(value) val(fn(index,value)) val([value1,…, valueN]) Get the value of the value attribute of the form element, or you can set the value of the value attribute of the form element. Function parameters can also be used. You can also select form options with specific value attribute values. For radio and select elements without mutiple set, only the last value value in the val parameter is valid
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
JavaScript Engines: Comparing Implementations JavaScript Engines: Comparing Implementations Apr 13, 2025 am 12:05 AM

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

Python vs. JavaScript: The Learning Curve and Ease of Use Python vs. JavaScript: The Learning Curve and Ease of Use Apr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

From C/C   to JavaScript: How It All Works From C/C to JavaScript: How It All Works Apr 14, 2025 am 12:05 AM

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

JavaScript and the Web: Core Functionality and Use Cases JavaScript and the Web: Core Functionality and Use Cases Apr 18, 2025 am 12:19 AM

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

JavaScript in Action: Real-World Examples and Projects JavaScript in Action: Real-World Examples and Projects Apr 19, 2025 am 12:13 AM

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

Understanding the JavaScript Engine: Implementation Details Understanding the JavaScript Engine: Implementation Details Apr 17, 2025 am 12:05 AM

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python vs. JavaScript: Community, Libraries, and Resources Python vs. JavaScript: Community, Libraries, and Resources Apr 15, 2025 am 12:16 AM

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

Python vs. JavaScript: Development Environments and Tools Python vs. JavaScript: Development Environments and Tools Apr 26, 2025 am 12:09 AM

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

See all articles