The example in this article describes the usage of attr() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:
This method sets or returns the attribute value of the matching element.
The attr() method has different functions depending on the parameters.
Grammar structure 1:
Get the attribute value of the specified attribute of the first matching element.
Parameter list:
Example code:
In the above code, clicking the button can pop up the class attribute value of the first element in the matching element collection.
Grammar structure 2:
Sets the attribute value for the specified attribute of the matching element.
Parameter list:
实例代码:
以上代码中, 当点击按钮的时候,能够重新设置div元素的class属性值。
语法结构三:
将“名/值”形式的对象设置为匹配元素的属性。可以一次性设置多组“名/值”对,对匹配元素属性进行设置。
参数列表:
Example code:
Welcome to Script House |
In the above code, you can set the width and height of the cell.
Syntax structure four: Set attribute values through function return values.
Parameter list:
实例代码: