你可以在 jQuery 中做類似的事情(a || b).click()嗎?
我試圖在單擊 a 或 b 時發生一些事情。在下面的示例中,我希望它在任何地方顯示button[i],因為它menubutton[i]旁邊有一個,這樣當點擊 abutton[i]或時,一切都可以發生menubutton[i]。
for (let i = 0; i < 4; i ) {
$(button[i]).click(function() {
if (divClosed[i]) {
$('#icons-pattern-main').css({
'height': '920px',
'clip-path': 'none',
'transition': '0.2s linear'
});
$('#text').css('display', 'none')
$('#textpers').css('display', 'flex')
$('#textpers').text(pers[i])
$('.header').mouseleave(function() {
setTimeout(function() {
$('#textpers').text("τι τ?ξη ε?σαι;")
}, 5000);
})
for (let x = 0; x < 4; x ) {
(divClosed[x]) = true
$(ShEl[x]).hide();
}
for (let x = 0; x < 6; x ) {
$(ShElinner[x]).hide();
}
divClosed[i] = false
$(ShEl[i]).css('display', 'flex');
if (i > 1) {
$('#icons-pattern-main').css('height', '520')
for (let x = 0; x < 6; x ) {
$(option[x]).click(function() {
$(ShElinner[x]).show()
$(ShEl[i]).hide()
$('#icons-pattern-main').css('height', '920')
subOpen = true
if (subOpen) {
$(button[i]).click(function() {
$(ShElinner[x]).hide()
subOpen = false
});
}
});
}
}
} else {
$('#icons-pattern-main').css({
'height': '420px',
'clip-path': 'polygon(0 0, 100% 0, 100% 59%, 44% 59%, 50% 100%, 56% 59%, 0 59%)',
'transition': '0.2s linear'
});
divClosed[i] = true;
$(ShEl[i]).hide()
$(ShElinner).hide()
$('#text').css('display', 'flex')
$('#textpers').css('display', 'none')
}
});
}
uj5u.com熱心網友回復:
$('.class1, .class2').on('click', some_function);
要么:
$('.class1').add('.class2').on('click', some_function);
這也適用于現有物件:
const $class1 = $('.class1');
const $class2 = $('.class2');
$class1.add($class2).on('click', some_function);
uj5u.com熱心網友回復:
通常,您可以使用CSS 選擇器選擇多個元素。
因此,您可以使用逗號( ,) 分隔多個選擇器,如下所示:
$(".a,.b").click()
.add()在您的情況下,您可以使用Lennard K 建議的函式向選擇器添加元素,如下所示:
$(button[i]).add(menubutton[i]).click()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/437471.html
標籤:jQuery
