I'm new with Javascript and Jquery and I'm facing a small problem.(我是Javascript和Jquery的新手,现在遇到了一个小问题。)
I'm trying to make sure that if a given link exists, hovering over this link will bring up a popup with the fadeToggle().(我试图确保如果存在给定的链接,将鼠标悬停在此链接上将弹出带有fadeToggle()的弹出窗口。) So I wrote this code that works:(所以我写了下面的代码:) if ($('.link-1')) {
$('.link-1').mouseover(function () {
$('.popup-1').fadeToggle();
})
.mouseout(function () {
$('.popup-1').fadeToggle();
})
}
But, instead of repeating it ten times, I wanted to write a loop, like this:(但是,我不想重复十次,而是想编写一个循环,如下所示:)
var number = 0;
while (number < 10) {
var popup = '.popup-' + number;
var link = '.link-' + number;
if ($(link)) {
$(link).mouseover(function () {
$(popup).fadeToggle();
})
.mouseout(function () {
$(popup).fadeToggle();
})
}
number++;
}
But it does not work.(但这行不通。) Could you help me please ?(请问你能帮帮我吗 ?)
I thank you in advance !(我提前谢谢你 !)
ask by innocent-musica translate from so