我正在使用以下JavaScript下拉菜单,在所有浏览器中都可以完美运行,除了新的Windows Edge。
它显示以下错误:
SCRIPT438:对象不支持属性或方法“matches”
脚本:
/* 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) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
我从http://www.w3schools.com/howto/howto_js_dropdown.asp获取了脚本,我认为它应该适用于所有平台。现在我已经实现了它,在Edge浏览器中遇到了问题。