gpt4 book ai didi

javascript - 单击它时不显示选项

转载 作者:行者123 更新时间:2023-11-30 09:56:47 24 4
gpt4 key购买 nike

我正在制作一个选项按钮(右上方的树点)。单击它时,必须显示选项。再次单击,选项隐藏。下面是我的代码,但它不起作用。你能看看吗?

$("body").ready(function () {
$(document).on("click", ".options-knop", function() {

if (this.nextSibling.style.display == "none"){
this.nextSibling.style.display = 'block !important';
} else {
this.nextSibling.style.display = 'none';
}
});
});
.img-wrapper {
width: 100px;
height: 100px;
overflow: hidden;
border-radius: 100%;
float: left;
margin: 5px;
}

.img-container {
height: 100px;
}

.artist {
transition: background-color 0.5s, color 0.5s;
cursor: pointer;
}

.artist-outer {
margin: 5px 0;
padding: 10px 5px;
}

.artist .naam {
width: 190px;
}

.options-knop {
position: absolute;
top: 15px;
left: 325px;
text-align: center;
line-height: 30px;
font-weight: bold;
width: 30px;
height: 30px;
border-radius: 100%;
color: black !important;
transition: background-color 0.5s, color 0.5s;
}

.artist-outer:nth-child(6n+4),
.artist-outer:nth-child(6n+5),
.artist-outer:nth-child(6n+6) {
background-color: #eeeeee;
}

.artist:nth-child(6n+4) .options-knop,
.artist:nth-child(6n+5) .options-knop,
.artist:nth-child(6n+6) .options-knop {
background-color: white;
}
.artist:nth-child(6n+1) .options-knop,
.artist:nth-child(6n+2) .options-knop,
.artist:nth-child(6n+3) .options-knop {
background-color: #eeeeee;
}

.options-knop:hover{
background-color: #a3a3a3 !important;
color: white !important;
}

.artist-outer:hover{
background-color: #545454 !important;
color: white !important;
}

.options-list {
display: none;
position: absolute;
z-index: 1;
top: 50px;
left: 260px;
}

.options-list ul {
padding: 0;
}

.naam {
max-height: 40px;
overflow: hidden;
}

.list-group {
padding-left: 0;
margin-bottom: 20px
}

.list-group-item {
position: relative;
display: block;
padding: 10px 15px;
margin-bottom: -1px;
background-color: #fff;
border: 1px solid #ddd
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<div class='clearfix col-md-4 artist-outer' id='656556255'>
<div class='artist'>
<div class='artist-info'>
<div class='img-wrapper'>
<img style="width:100px" src='http://i.stack.imgur.com/kYnSM.gif'/>
</div>
<p class='naam'><b>Random naam</b></p>
<p>Volgers op Spotify: XXX</p>
</div>
<div class='options-knop'>...</div>
<div class='options-list list-group' style='display: none;'>
<a class='list-group-item'>Toon albums</a>
<a class='list-group-item'>Profiel</a>
</div>
</div>
</div>

最佳答案

因为您使用的是 JQuery,所以您可以使用函数 css() :

if ( $(this).next().css('display') == "none")
$(this).next().show();
else
$(this).next().hide();

或者简单地使用 toggle() 切换您的 div show/hide 的显示不使用条件:

$(this).next().toggle();

希望这对您有所帮助。

关于javascript - 单击它时不显示选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33594700/

24 4 0
文章推荐: javascript - 我如何告诉 CSS 重新计算 :first-of-type after DOM dynamically changes?
文章推荐: machine-learning - LIBSVM 的数据格式
文章推荐: machine-learning - 输入神经元应该有输入权重吗?
文章推荐: javascript - 如何在
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com