📅  最后修改于: 2020-11-26 01:20:11             🧑  作者: Mango
jQuery toggleCLass()方法用于从所选元素中添加或删除一个或多个类。此方法在添加和删除一个或多个类名之间切换。它检查每个元素是否有指定的类名。如果已经设置了类名,则将其删除;如果缺少类名,则将其添加。
这样,它会产生切换效果。它还可以帮助您通过使用switch参数指定仅添加或仅删除。
句法:
$(selector).toggleClass(classname,function(index,currentclass),switch)
Parameter | Description |
---|---|
classname | It is a mandatory parameter. It specifies one or more class name to add or remove. If you use several classes then separate them by space. |
function (index, currentclass) | It is an optional parameter. It specifies one or more class names that you want to add or remove.
|
switch | It is also an optional parameter. It is a Boolean value which specifies whether the class should be added (true) or removed (false). |
让我们以一个示例来演示jQuery toggleClass()方法的效果。
Hello! javatpoint.com
This is popular tutorial website.
Note: Click repeatedly on the button to see the toggle effect.
toggleClass demo
www.javatpoint.com
Java Tutorial
SQL Tutorial
Android Tutorial
HTML Tutorial
etc.
toggleClass demo