/* When the user clicks on the button, toggle between hiding and showing the dropdown content */ function myFunction() { document.getElementById("myDropdown").classList.toggle("show"); } // Close the dropdown menu if the user clicks outside of it window.onclick = function(event) {...
可以使用onBlur()。但为了做到这一点,你需要添加tabindex="0"到调用元素,即调用下拉菜单显示的元素。
// Close the dropdown if the user clicks outside of it window.onclick = function(e) { if (!e.target.matches('.dropbtn')) { var allDropdowns = document.getElementsByClassName('dropdown-content'); //close all other dropdowns for (var i = 0; i < allDropdowns.length; i++) { ...
How can I close a dropdown on click outside?, I've made a directive to address this similar problem and I'm using Bootstrap. But in my case, instead of waiting for the click event outside the element to close the current opened dropdown menu I think it is bette...
Close the menu when clicking outside We can handle theclickevent ofdocument, and determine if user clicks outside of the menu: ele.addEventListener('contextmenu',function(e){...document.addEventListener('click',documentClickHandler);});// Hide the menu when clicking outside of itconstdocument...
案例分析 导航栏里面的li都要有鼠标经过效果,所以需要循环注册鼠标事件 核心原理:当鼠标经过li里面的第二个孩子ul显示,当鼠标离开,则ul隐藏 代码实现 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name...
Alternatively, specify static for a backdrop which doesn't close the modal on click. keyboard boolean true Closes the modal when escape key is pressed show boolean true Shows the modal when initialized. remote path false This option is deprecated since v3.3.0 and has been removed in v4. ...
让警告框监听具有 data-dismiss="alert" 属性的后裔元素的点击(click)事件。(如果是通过 data 属性进行的初始化则无需使用) $().alert('close') 关闭警告框并从 DOM 中将其删除。如果警告框被赋予了 .fade 和.in 类,那么,警告框在淡出之后才会被删除。 事件 Bootstrap 的警告框插件对外暴露了一些可以被监听...
让警告框监听具有 data-dismiss="alert" 属性的后裔元素的点击(click)事件。(如果是通过 data 属性进行的初始化则无需使用) $().alert('close') 关闭警告框并从 DOM 中将其删除。如果警告框被赋予了 .fade 和.in 类,那么,警告框在淡出之后才会被删除。 事件 Bootstrap 的警告框插件对外暴露了一些可以被监听...
让警告框监听具有 data-dismiss="alert" 属性的后裔元素的点击(click)事件。(如果是通过 data 属性进行的初始化则无需使用) $().alert('close') 关闭警告框并从 DOM 中将其删除。如果警告框被赋予了 .fade 和.in 类,那么,警告框在淡出之后才会被删除。 事件 Bootstrap 的警告框插件对外暴露了一些可以被监听...