我正在使用以下 JavaScript 下拉菜单,它在除新的 Windows Edge 之外的所有浏览器中都能完美运行。
它显示此错误:
SCRIPT438:对象不支持属性或方法“匹配”
脚本:
/* 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 中遇到了问题。