2 回答

TA贡献1810条经验 获得超5个赞
我无法测试这个,但看来你在应该使用“事件”的地方使用了“这个”
“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条经验 获得超4个赞
我无法测试这个,但看来你在应该使用“事件”的地方使用了“这个”
“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();
}
}
}
}
添加回答
举报