Bootstrap-select.js - 选择一个选项后,整个选择消失

问题描述:

我试图为我的网站(Magento版本1.9.1.0)设置bootstrap-select.js,并且我遇到了一些问题解决。Bootstrap-select.js - 选择一个选项后,整个选择消失

一切都被载入完美的,但是当我通过获取element.style到像这样整个选择消失选择下拉列表中选择一个选项:

style="display:none;" 

而且在Firebug它说:

element.style { 
display: none; 
} 

在这里看到的视觉形象:http://i.imgur.com/cg1jkOp.jpg?1

的问题是我不知道这个造型是从哪里来的,所以我决定CHEC k在FireBug中打断属性改变,看看它说了什么。该代码jQuery的(jQuery的2.1.3.min.js)之际,您可以在此图像中看到:http://i.imgur.com/Jbu8TCx.jpg?1

这是我在我的<head>部分:

<link rel="stylesheet" href="http://localhost/sg-magento/skin/frontend/ultimo/default/css/bootstrap/bootstrap.min.css"> 
<link rel="stylesheet" href="http://localhost/sg-magento/skin/frontend/ultimo/default/css/bootstrap/bootstrap-select.min.css"> 

<script type="text/javascript" src="http://localhost/sg-magento/js/infortis/jquery/jquery-2.1.3.min.js"></script> 

<script type="text/javascript" src="http://localhost/sg-magento/skin/frontend/ultimo/default/js/bootstrap/bootstrap.min.js"></script> 
<script type="text/javascript" src="http://localhost/sg-magento/skin/frontend/ultimo/default/js/bootstrap/bootstrap-select.min.js"></script> 

<script type="text/javascript"> 
jQuery(document).ready(function($) { 
    $('.selectpicker').selectpicker(); 
}); 
</script> 

我到哪里去从这里?我该如何解决这个问题?看起来像是一件小事,但现在真的让我很紧张。一直试图找出很长一段时间。

希望有人愿意尝试帮助。

谢谢。

我有类似的问题,当select在提交和重新呈现Backbone模板时消失。在我的情况下调用$('。selectpicker')。selectpicker('render');修复。

+0

我迟到了,但是如果您收到此通知,您是否介意告诉我您将代码放在哪里? – IRGeekSauce 2017-02-08 01:10:37

这是因为用于Bootstrap和Prototype的冲突。查看更多详情here。 创建一个新的JS文件并在其中添加以下代码。

if (Prototype.BrowserFeatures.ElementExtensions) { 
var disablePrototypeJS = function (method, pluginsToDisable) { 
     var handler = function (event) { 
      event.target[method] = undefined; 
      setTimeout(function() { 
       delete event.target[method]; 
      }, 0); 
     }; 
     pluginsToDisable.each(function (plugin) { 
      jQuery(window).on(method + '.bs.' + plugin, handler); 
     }); 
    }, 
    pluginsToDisable = ['collapse', 'dropdown', 'modal', 'tooltip', 'popover']; 
disablePrototypeJS('show', pluginsToDisable); 
disablePrototypeJS('hide', pluginsToDisable);} 

玩得开心:)

$(".dropdown-menu > ul > li").click(function() { 
$('.bootstrap-select').attr('style', ''); 
$(this).parent('.bootstrap-select').attr('style', ''); 
}); 

这将覆盖cuases这个问题任何冲突。我不相信以前的答案是正确的。矿山DEF不是一个答案。但它会解决问题,直到可以花更多时间找到冲突的真正根源。原型可能是原因,但原型答案不起作用!