Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Передача переменной ! (https://javascript.ru/forum/misc/5992-peredacha-peremennojj.html)

Andrei 06.11.2009 07:50

Передача переменной !
 
Здравствуйте !
Неполучается передать i функции screen_win !

function init() {

for (var i = 1; i < 5; i++) {
document.getElementById("but_"+i).onmouseover = function(){ screen_win(i)};
document.getElementById("but_"+i).onmouseout = function () { off()};
}

}


function screen_win(but) {
alert (but); //Здесь выводит пять при наведении на любую из кнопок !
if (but== 1) {

document.getElementById('screen_win').style.left = "3px"

document.getElementById('screen_img').src = "1.jpeg";

} else if (but == 2) {

document.getElementById('screen_win').style.left = "68px"

document.getElementById('screen_img').src = "2.jpeg";

} else if (but == 3) {

document.getElementById('screen_win').style.left = "150px"

document.getElementById('screen_img').src = "1.jpeg";

} else if (but == 4) {

document.getElementById('screen_win').style.left = "220px"

document.getElementById('screen_img').src = "2.jpeg";

}

}

Riim 06.11.2009 09:28

http://javascript.ru/basic/closure#p...-ispolzovaniya

Andrei 06.11.2009 10:05

Спасибо !


Часовой пояс GMT +3, время: 11:39.