2 回答

TA貢獻1810條經(jīng)驗 獲得超5個贊
我無法測試這個,但看來你在應(yīng)該使用“事件”的地方使用了“這個”
“this”指的是窗口對象。
// 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];
/// here is where the behaviour needs to be added //////////
if (openDropdown.classList.contains('show') &&
($(event.target).hasClass('menubtns'))) {
openDropdown.classList.remove('show');
console.log('you have clicked an option');
} else {
console.log('not clicked on an option')
openDropdown.classList.remove('show');
mainpageaccessibility();
}
}
}
}

TA貢獻1966條經(jīng)驗 獲得超4個贊
我無法測試這個,但看來你在應(yīng)該使用“事件”的地方使用了“這個”
“this”指的是窗口對象。
// 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];
/// here is where the behaviour needs to be added //////////
if (openDropdown.classList.contains('show') &&
($(event.target).hasClass('menubtns'))) {
openDropdown.classList.remove('show');
console.log('you have clicked an option');
} else {
console.log('not clicked on an option')
openDropdown.classList.remove('show');
mainpageaccessibility();
}
}
}
}
添加回答
舉報