在Firefox上点击鼠标右键,Bootstrap下拉菜单消失 [英] Bootstrap dropdown disappear with right-click on Firefox

查看:153
本文介绍了在Firefox上点击鼠标右键,Bootstrap下拉菜单消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些twitter-bootstrap和firefox的问题。
我有一个按钮和一个带有输入文本的下拉菜单。如果我右键单击输入(例如右键单击+粘贴),Firefox将关闭下拉列表。那么相当无聊。



有没有解决方案来防止这种行为?



谢谢!

解决方案

作为一个立即的间谍解决方案,您可以使用以下几行来阻止点击事件传播当点击事件右键单击



JS



  $ (文件).on('click',function(e){
e.button === 2& amp; e.stopImmediatePropagation()
})

这需要放在 jQuery 加载和 Bootstrap 加载之间。 >

Plunk



然而,这是一个相当钝的方法,如果可能,你可能会做更好的事情。






更新



规避这个issu的一种方法e以更有针对性的方式禁用原始事件监听器,并用一个检查右键单击的消息进行替换。



JS



  //获取对原始处理程序的引用
var _clearMenus = $ ._ data(document,events)。click.filter(function(el ){
return el.namespace ==='data-api.dropdown'&& el.selector === undefined
})[0] .handler;

//禁用旧的监听器
$(document)
.off('click.data-api.dropdown',_clearMenus)
.on('click .data-api.dropdown',function(e){
//只在没有右键单击
e.button === 2 || _clearMenus()
}时调用处理程序)

与上一个示例不同,此代码需要在 Bootstrap有



Plunk


I have some kind of problem with twitter-bootstrap and firefox. I have a button and a dropdown menu with an input text. If I right click on the input ( for right-click + Paste for example), firefox closes the dropdown. And that quite boring.

Is there any solution for prevent that behaviour ?

Thanks !

解决方案

As an immediate stop-gap workaround you can use something along the following lines to prevent the click event from propagating when the click event is a right-click

JS

$(document).on('click', function(e) {
  e.button === 2 && e.stopImmediatePropagation()
})

This would need to be placed between jQuery loading and Bootstrap loading.

Plunk

However, this is a rather blunt approach and you'd probably be better off doing something more subtle if possible.


Update

One way to circumvent this issue in a more targeted manner is to disable the original event listener and replace it with one that checks for right-clicks first.

JS

// obtain a reference to the original handler
var _clearMenus = $._data(document, "events").click.filter(function (el) {
    return el.namespace === 'data-api.dropdown' && el.selector === undefined
  })[0].handler;

// disable the old listener
$(document)
  .off('click.data-api.dropdown', _clearMenus)
  .on('click.data-api.dropdown', function (e) {
    // call the handler only when not right-click
    e.button === 2 || _clearMenus()
  })

Unlike the previous example, this code would need to run after Bootstrap has loaded.

Plunk

这篇关于在Firefox上点击鼠标右键,Bootstrap下拉菜单消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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