JQ methods: html(), text(), val(), attr(), prop()

1、html()

It is equivalent to the innerHTML method in JS, you can get the label, no parameter is to get the value, and the parameter is to set the value.
Insert picture description here
Insert picture description here

2、text()

It is equivalent to innerText in JS. There is no parameter to get the value, and there is a parameter to set the value. Only get the text, not the label.
Insert picture description here
Insert picture description here

3、val()

Equivalent to value, often used for form operations, no parameter is to get, and parameter is to set the value

Insert picture description here
Insert picture description here

4、attr()

The attr() method sets or returns the attribute value of the selected element.
Insert picture description here
Insert picture description here

5、prop()

A parameter, if it is checked in the form, is to judge whether the element has the attribute (whether it is selected). If it is id, class and so on, get the corresponding value. The two parameters are to set the attributes and values ​​of the element

6. When to use prop() and when to use attr()

Official suggestion: Use prop() for properties with two property values ​​of true and false, such as checked, selected or disabled, and use attr() for others.

Use prop() to get the checked state of the check box, and the return is true or false
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_41504815/article/details/114644262