📅  最后修改于: 2020-10-23 07:29:44             🧑  作者: Mango
本章将讨论toggleClass()方法,这是一个有用的新类。 toggleClass()方法从匹配的元素集中的每个元素添加或删除一个或多个类。
toggleClass()方法的基本语法如下:
.toggleClass( className [, switch ] [, duration ] [, easing ] [, complete ] )
Sr.No. | Parameter & Description |
---|---|
1 |
className This is a String and represents the CSS class name, or space-delimited list of class names, to be added, removed, or toggled. |
2 |
switch This is of type Boolean and if specified, forces the toggleClass() method to add the class if true, or to remove the class if false. |
3 |
duration This is of type Number or String and optionally provides one of slow, normal, fast, or the duration of the effect in milliseconds. If omitted, the animate() method determines the default. Its default value is 400. |
4 |
easing The name of the easing function to be passed to the animate() method. |
5 |
complete This is a callback method called for each element when the effect is complete for this element. |
在1.9版中,此方法现在支持子选项,该选项还将为后代元素设置动画。
.toggleClass( className [, switch ] [, options ] )
Sr.No. | Parameter & Description |
---|---|
1 |
className This is a String and represents the CSS class name, or space-delimited list of class names, to be added, removed, or toggled. |
2 |
switch This is of type Boolean and if specified, forces the toggleClass() method to add the class if true, or to remove the class if false. |
3 |
options This represents all animation settings. All properties are optional. Possible values are −
|
以下示例演示了toggleClass()方法的用法。
jQuery UI Switch Class Example
Welcome to Tutorials Point
让我们将上面的代码保存在HTML文件toggleclassexample.htm中,并在支持javascript的标准浏览器中将其打开,您还必须看到以下输出。现在,您可以处理结果了-
单击“切换”按钮以查看如何更改文本的CSS类。