使用jQuery获取元素的类列表

蹲街弑〆低调 提交于 2020-08-09 22:42:23

问题:

Is there a way in jQuery to loop through or assign to an array all of the classes that are assigned to an element? jQuery中是否有一种方法可以循环或将分配给元素的所有类分配给数组?

ex. 例如

<div class="Lorem ipsum dolor_spec sit amet">Hello World!</div>

I will be looking for a "special" class as in "dolor_spec" above. 我将在上面的“ dolor_spec”中寻找“特殊”类。 I know that I could use hasClass() but the actual class name may not necessarily be known at the time. 我知道我可以使用hasClass(),但是实际的类名可能在那时不一定是已知的。


解决方案:

参考一: https://stackoom.com/question/59Gw/使用jQuery获取元素的类列表
参考二: https://oldbug.net/q/59Gw/Get-class-list-for-element-with-jQuery
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!