使用Bootstrap的下拉菜单。这是一个简单的过程,以下是它的工作原理:
如果用户徘徊&#34;加入购物车&#34;如果没有选择任何尺寸,按钮会将按钮<span>
中的文字更改为&#34;选择尺寸&#34;。如果用户在范围文本为&#34时单击按钮,则选择尺寸&#34;它应该切换引导下拉列表。这是代码:
var size = true;
$('#cart-btn').mouseenter(function(){
if(size==true){
$(this).find('span').html('NEED SIZE');
}
});
$('#cart-btn').mousedown(function(){
if(size==true){
$(".cart-dd.dropdown-toggle").dropdown("toggle");
}
});
$('#cart-btn').mouseleave(function(){
$(this).find('span').html('ADD TO CART');
});
如果我使用.click
或.mouseup
下拉切换切换不会触发(切换/打开)它只会触发.mousedown
为什么会这样?
注意:我在这里有一些额外的代码:
$(".dropdown-menu li label").click(function(){
var selected = $(this).text();
$(this).parents('#cart-dd').find('.dropdown-toggle').html(selected);
size = false;
});
这会更改下拉列表的标签(几乎无关紧要,但可能会导致冲突?)
答案 0 :(得分:0)
将您的函数mouseenter,mousedown,mouseleave更改为:
对于较旧的Jquery
$("#cart-btn").live("mousedown mouseenter mouseleave",function(){//dosomething});
对于最新的jquery:
$("#cart-btn").on("mousedown mouseenter mouseleave",function(){//dosomething});