removeClass()方法是jQuery中的一个内置方法,用于从所选元素中删除一个或多个类名。
null
语法:
$(selector).removeClass(class_name, function(index, current_class_name))
参数: 该函数接受两个参数,如下所述:
- 类别名称: 它是可选参数,用于指定要删除的类名(一个或多个类)。多个用空格分隔的类名。
- 功能: 它是可选参数,返回一个或多个需要删除的类名。
- 索引: 此参数用于返回元素的索引。
- 当前_类_名称: 此参数返回选定元素的类名。
返回值: 此方法返回具有指定移除类名的选定元素。
以下示例说明了jQuery中的removeClass()方法:
例1:
< html > < head > < title >The removeClass Method</ title > < script src = </ script > <!-- jQuery code to show the working of this method --> < script > $(document).ready(function() { $("p").click(function() { $("p").removeClass("GFG"); }); }); </ script > < style > .GFG { font-size: 120%; color: green; font-weight: bold; font-size: 35px; } div { width: 50%; height: 200px; padding: 20px; border: 2px solid green; } </ style > </ head > < body > < div > <!-- click on any paragraph and see the change --> < p class = "GFG" >Welcome to</ p > < p class = "GFG" >GeeksforGeeks</ p > </ div > </ body > </ html > |
输出: 在点击段落之前: 点击段落后:
例2: 此示例不包含参数。这将删除选定元素的所有类。
<!DOCTYPE html> < html > < head > < title >The removeClass Method</ title > < script src = </ script > <!-- jQuery code to show the working of this method --> < script > $(document).ready(function() { $("p").click(function() { $("p").removeClass(); }); }); </ script > < style > .GFG { font-size: 120%; color: green; font-weight: bold; font-size: 35px; } div { width: 300px; height: 200px; padding: 20px; border: 2px solid green; } </ style > </ head > < body > < div > <!-- click on any paragraph and see the change --> < p class = "GFG" >Welcome to </ p > < p class = "GFG" >GeeksforGeeks!</ p > </ div > </ body > </ html > |
输出: 在点击段落之前: 点击段落后:
相关文章:
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END