我正在使用以下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');
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
得到了以下脚本:http://www.w3schools.com/howto/howto_js_dropdown.asp,我认为它与所有平台兼容.现在我已经实现了它,并在Edge中遇到了问题.