我使用以下JavaScript下拉菜單,它適用於除新Windows Edge之外的所有瀏覽器。Dropdown Javascript錯誤:對象不支持屬性或方法「匹配」
它顯示這個錯誤:
SCRIPT438: Object doesn't support property or method 'matches'
腳本:http://www.w3schools.com/howto/howto_js_dropdown.asp我認爲將與所有平臺兼容:
/* 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');
}
}
}
}
從拿到劇本。現在我已經實現了它,並在Edge中遇到了問題。
謝謝你這麼多@Marc孔特這是一個很大的幫助:-) – Jones
這固定它對於我來說,非常感謝馬克 – Evolve