gpt4 book ai didi

javascript - jQuery 显示/隐藏 div 在 Chrome 中不起作用

转载 作者:行者123 更新时间:2023-12-03 09:29:29 31 4
gpt4 key购买 nike

我是 jQuery 的新手。我有一个 a.acessaPonto,如果单击它,添加/删除类 a.acessaPonto.Selected 并显示/隐藏 div.AcessaPontoAtendimento。我有这样的代码。在 Firefox 和 IE 中运行良好,但在 Chrome 中不起作用。

  $( document ).ready(function() {
$('.acessaPonto').click(function() {
$(this).toggleClass('Selected');
if ($(this).hasClass('Selected'))
$('.AcessaPontoAtendimento').css("display", "inline-block");
else
$('.AcessaPontoAtendimento').css('display', 'none');
});
});
.acessaPonto{
background-color:blue;
}
.acessaPonto.Selected{
background-color:red;
}

.AcessaPontoAtendimento{
display:none;
background-color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>

</head>
<body>
<a href="#" class="acessaPonto">Click</a>
<div class="AcessaPontoAtendimento">
<p>Lorem ipsum dolor color</p>
</div>
</body>
</html>

有人知道我的代码有什么问题吗?

最佳答案

$('.acessaPonto').click(function (e) {
e.preventDefault();
$(this).toggleClass('Selected');
$('.AcessaPontoAtendimento').toggle( $(this).hasClass('Selected') );
});

如果您的 .acessaPonto 位于 a 标记上,则需要 e.preventDefault(),否则不需要。

关于javascript - jQuery 显示/隐藏 div 在 Chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31562882/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com