📜  jQuery addClass()

📅  最后修改于: 2020-11-26 01:18:12             🧑  作者: Mango

jQuery addClass()

addclass()方法用于将一个或多个类名称添加到所选元素。此方法仅用于将一个或多个类名称添加到类属性,而不会删除现有的类属性。

如果要添加多个类,请用空格分隔类名称。

句法:

$(selector).addClass(classname,function(index,oldclass)) 

jQuery addClass()方法的参数

Parameter Description
Classname It is a mandatory parameter. It specifies one or more class names which you want to add.
Function (index, currentclass) It is an optional parameter. It specifies a function that returns one or more class names to be added.
  • Index: It is used to provide the index position of the element in the set.
  • Currentclass: It is used to return the current class name of the selected element.

jQuery addClass()方法的示例

让我们以一个示例来演示jQuery addclass()方法的效果:









This is a heading

This is a paragraph.

This is another paragraph.