参见here
 (为此,我可以让Kittenz)



//Initially the need size should be shown
var need_size=true;
//when the cursor enters the button area
$('#cart-btn').mouseenter(function(){
 //we check if the message needs to be shown
 if(need_size==true){
    //if yes, show it
    $(this).find('span').html('NEED SIZE');
  }
});
$('#cart-btn').mouseleave(function(){
    //when the cursor leaves the button, we restore back the text
    $(this).find('span').html('ADD TO CART');
});

$(".dropdown-menu li label").click(function(){
  var selected = $(this).text();
  $(this).parents('#cart-dd').find('.dropdown-toggle').html(selected);
  //we disable the need size text to be shown once an option is selected
  need_size=false;
});


当显示跨度“ NEED SIZE”消息时,如果用户单击按钮,我将如何打开下拉菜单。这是我的意思的错误代码示例:

 if(need_size==true){
    //if yes, show it
    $(this).find('span').html('NEED SIZE').click('span').find('.dropdown-toggle').addClass('open');
  }

最佳答案

从引导documentation开始

$().dropdown('toggle')



  切换给定导航栏或选项卡式导航的下拉菜单。


因此用于显示/隐藏下拉菜单,例如在您声明的mouseenter事件期间

if(need_size==true){
    $(".cart-dd.dropdown-toggle").dropdown("toggle");
}

07-24 18:59
查看更多