你知道为什么在 hasClass
之后使用 removeClass
会给我 Uncaught TypeError: undefined is not a function
吗?
在下面的代码中,警报不会被执行,因为上面的代码产生错误。
$("input[type='button']").hasClass("scroll").removeClass("inactive");
alert("success");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
有人可以提供其他方法来实现我的目标吗?
最佳答案
jQuery hasClass
返回 bool 值,它没有 removeClass
方法。在您的情况下,最好将类选择器放在 $
调用
$("input[type='button'].scroll").removeClass("inactive");
关于jquery - hasClass 不起作用后删除Class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29468142/