将鼠标悬停时的按钮替换为另一个不起作用的按钮jQuery
Replace a button with another on hover not working jQuery
我有两个按钮,我想一次只显示一个按钮,但在悬停时,该按钮将被另一个按钮取代,并返回到mouseout上的第一个按钮。
我给出了下面的一段代码,但在悬停时,它一直在两个按钮之间来回移动,最好的方法是什么?
$(document).ready(function() {
$('.price').on('mouseover',function() {
$(this).css('display','none');
$(this).next('.buy').css('display','block');
});
$('.price').on('mouseout',function() {
$(this).css('display','block');
$(this).next('.buy').css('display','none');
});
});
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="price-div" style="
display: block;
">
<button type="button" class="btn btn-default price" style="display: block; z-index: 9999999999999; position: absolute;"> $589.50 <!-- <button type="button" class="btn btn-default compare"><i class="fa fa-bar-chart"></i>Compare</button> -->
</button><button type="button" class="btn btn-default buy" value="Add to Cart" onclick="addToCart('43');" style="display: none; z-index: 999999; position: absolute;"><i class="fa fa-shopping-cart"></i> Add To Cart</button>
</div>
589.50美元比较-->添加到购物车它之所以一直显示/隐藏,是因为一旦显示.buy
,鼠标输出就会被触发,所以把鼠标输出放在.buy
元素上
$('.price').on('mouseover',function() {
$(this).css('display','none');
$(this).next('.buy').css('display','block');
});
$('.buy').on('mouseout',function() {
$(this).prev('.price').css('display','block');
$(this).css('display','none');
});
DEMO
相关文章:
- 单击转盘按钮后重定向到另一个页面
- 如何在单击按钮时显示一个分区,同时隐藏另一个分区
- jquery点击另一个网站上的按钮
- 如何使用Twitter引导程序点击按钮导航到另一个页面
- 将按钮链接到另一个页面的一部分
- Jquery:如果选中了另一个按钮,则为未选中按钮
- 如何将图像制作为按钮并将其重定向到另一个页面
- 单击输入时,将提交按钮设置为另一个
- 将按钮名称和值传递给另一个 JavaScript 页面
- 在单击按钮时激活按钮的悬停状态,直到单击另一个按钮(Javascript/JQuery)
- TinyMCE 将另一个事件添加到粗体和斜体按钮
- 禁用另一个元素内的元素,除非它是按钮
- 将搜索按钮从一个站点复制到另一个站点:此搜索按钮如何工作,以及如何重现其操作
- 具有双重功能的按钮:在_blank窗口中打开一个链接,再加上_self中的另一个链接
- 使用单选按钮参考另一个功能
- 单击单选按钮禁用另一个单选按钮
- 如何使Angular打开一个按钮并关闭另一个按钮
- 另一个按钮内的按钮不会;不能在Firefox(Angular Material)中工作
- 按钮onclick应该与参数一起重定向到另一个xhtml页面
- 如何通过单击另一个按钮使按钮可见