防止启动下拉列表关闭点击 [英] Preventing bootstrap dropdown from closing on click

查看:87
本文介绍了防止启动下拉列表关闭点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将复选框放在引导下拉列表中。我不想让点击关闭,但如果点击网站上的其他地方,我仍然希望关闭。我仍然想在下拉列表中点击点击其他JavaScript动作。我有一个与我想要的完全相反的例子。此示例关闭点击下拉列表,但在从下拉区域外部点击时保持打开状态。

  $(function() {
$('。dropdown.keep-open')。on({
shown.bs.dropdown:function(){
$(this).data('closable' ,
},
click:function(){
$(this).data('closable',true);
},
hide.bs.dropdown:function(){
return $(this).data('closable');
}
});
});

http://jsfiddle.net/KyleMit/ZS4L7/

解决方案

我终于明白了。代码如下:

  $(function(){
$('。dropdown.keep-open' .on({
shown.bs.dropdown:function(){
$(this).data('closable',false);
},
:function(event){
$(this).data('closable',false);
},
hide.bs.dropdown:function(event){
temp = $(this).data('closable');
$(this).data('closable',true);
return temp;
}
});
});

编辑:添加了第11行缺少的分号。


I am trying to put checkboxes in a bootstrap dropdown. I do not want the dropdown to close on click but I still want it close if they click else where on the website. I still want to fire off other javascript actions on click with in the dropdown. I have an example of the exact inverse of what I want. This example closes the drop down on click but keeps it open when clicked from the outside the dropdown area.

 $(function () {
     $('.dropdown.keep-open').on({
         "shown.bs.dropdown": function() {
             $(this).data('closable', false);
         },
         "click": function() {
             $(this).data('closable', true);
         },
         "hide.bs.dropdown": function() {
             return $(this).data('closable');
         }
     });
 });   

http://jsfiddle.net/KyleMit/ZS4L7/

解决方案

I finally got it. the code is below:

$(function() {
    $('.dropdown.keep-open').on({
        "shown.bs.dropdown": function() {
            $(this).data('closable', false);
        },
        "click": function(event) {
            $(this).data('closable', false);
        },
        "hide.bs.dropdown": function(event) {
            temp = $(this).data('closable');
            $(this).data('closable', true);
            return temp;
        }
    });
});

Edit: Added missing semicolon on line 11.

这篇关于防止启动下拉列表关闭点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆