请参阅here: (感谢I Can Has 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');
}
答案 0 :(得分:0)
引导程序documentation
$().dropdown('toggle')
切换给定导航栏或选项卡式导航的下拉菜单。
所以用来显示/隐藏下拉列表,例如在你声明的mouseenter事件中
if(need_size==true){
$(".cart-dd.dropdown-toggle").dropdown("toggle");
}