防止启动下拉列表关闭点击 [英] Preventing bootstrap dropdown from closing on click
本文介绍了防止启动下拉列表关闭点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$(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屋!
查看全文