gpt4 book ai didi

javascript - 隐藏和显示不适用于悬停()?

转载 作者:行者123 更新时间:2023-11-28 18:56:41 26 4
gpt4 key购买 nike

我可以看到悬停()正在工作,但它没有隐藏和显示 contact_numbers 类?我的代码有什么问题?

$(function() {
$("#hdCallUs").hover(function() {
$(this).find('.contact_numbers').show();
console.log('in')
}, function() {
$(this).find('.contact_numbers').remove()
console.log('out')
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li id="hdCallUs">
<span class="glyphicon glyphicon-earphone"></span>
<span class="call_txt">Call Us Now</span>

<div class="contact_numbers">
<li>999</li>
<li>888</li>
</div>
</li>

最佳答案

因为错误Dom html 中的结构

<ul>里面缺少 <div class="contact_numbers">怎么能<li>开始没有 <ul>

在你的问题中你写隐藏和显示不能与hover()一起使用?比为什么.remove()在你的代码中如果你想隐藏你的元素使用 .hide()看我的代码

$(function() {
$("#hdCallUs").hover(function() {
$(this).find('.contact_numbers').show();
console.log($(this).find('.contact_numbers'))
}, function() {
//$(this).find('.contact_numbers').remove() // this will remove element
$(this).find('.contact_numbers').hide() // this will hide
console.log('out')
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<ul>
<li id="hdCallUs">
<span class="glyphicon glyphicon-earphone"></span>
<span class="call_txt">Call Us Now</span>

<div class="contact_numbers">
<ul>
<li>999</li>
<li>888</li>
</ul>
</div>
</li>
</ul>

关于javascript - 隐藏和显示不适用于悬停()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33517909/

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