<分区>
我有这样一个元素:
<div class="one two three" id="waterhorse">horse</div>
当我在浏览器控制台中运行这段代码时:
$("#waterhorse").removeClass();
我明白了:
[<div id="waterhorse" class="one two three">horse</div>]
换句话说,它不起作用;它不会删除元素上的任何类。不幸的是,我无法在 jsfiddle 中重现它。
但是,我可以删除特定的类:
$("#waterhorse").removeClass("two");
此外,这将删除所有类:
$("#waterhorse").removeAttr("class");
知道为什么后者可以删除所有类,而前者不能吗?