我有个div
<div id="commonConsultationPopup" class="overlayPopup"></div>我想在页面加载时删除类。
我试过:
$(document).ready(function() {
$("#commonConsultationPopup").removeClass("overlayPopup");
});但这不管用。
发布于 2016-07-16 19:09:29
试试这个:
$(document).ready(function() {
$("#commonConsultationPopup").removeClass();
});但是它将从给定的div中删除所有类。
发布于 2016-07-16 18:31:12
我不相信这个函数能像你想的那样。从手册中:
遥控器(ClassName) 类型:字符串 要从每个匹配元素的class属性>移除一个或多个分隔空间的类。
请注意,手册中说它将从class属性中删除该类。它没有声明它将删除整个元素。
如果希望删除整个div,则需要.remove()函数。若要使用此方法,请使用查找器来定位div (可能是按类名?)然后打电话给remove()。
发布于 2016-07-16 18:50:30
若要删除文档就绪上的类,请使用以下JS:
jQuery(document).ready(function() {
$("#commonConsultationPopup").removeClass("overlayPopup");
});若要在加载窗口时从元素中删除类,请使用以下方法:
jQuery(window).load(function() {
$("#commonConsultationPopup").removeClass("overlayPopup");
});以下是完整的代码:
<!DOCTYPE html>
<html>
<head>
<title>Remove class example</title>
<!-- We are using jQuery 3.1.0 -->
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<!-- You can also use jQuery 12.1.4 like this -->
<!-- <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script> -->
</head>
<body>
<div class="overlayPopup" id="commonConsultationPopup"></div>
<script type="text/javascript">
// Use this if you want to wait for the page to be ready:
jQuery(document).ready(function($) {
$("#commonConsultationPopup").removeClass("overlayPopup");
});
// Use this instead if you want to wait for the page to load:
// jQuery(window).load(function() {
// $("#commonConsultationPopup").removeClass("overlayPopup");
// });
</script>
</body>
</html>祝你好运万事如意。
https://stackoverflow.com/questions/38414271
复制相似问题