如何通过 jQuery 或 JavaScript 一步修改多个类的类列表?
我的表单中有几个类
<div class="form-group has-error has-feedback">...</div>
<div class="form-group has-error has-feedback">...</div>
<div class="form-group has-error has-feedback">...</div>
如何删除除 form-group
之外的所有类?
<div class="form-group">...</div>
<div class="form-group">...</div>
<div class="form-group">...</div>
最佳答案
您可以使用 .removeClass()方法。
$(".form-group.has-error.has-feedback").removeClass("has-error has-feedback");
来自 jQuery 文档:
Description:
Remove a single class, multiple classes, or all classes from each element in the set of matched elements.
...
If a class name is included as a parameter, then only that class will be removed from the set of matched elements. If no class names are specified in the parameter, all classes will be removed.
关于javascript - 修改多个元素的类列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34568420/