I am developing a code for user interaction, in which he should light a lamp by hovering his mouse over it, and break it down with click
on it.
The iteration of hover
is normally occurring, but click
does not work in IE , Chrome .
Can anyone help?
function MudaLampada(tipo) {
if (tipo == 1) {
arquivo = "http://i.stack.imgur.com/ybxlO.jpg";
}
if (tipo == 2) {
arquivo = "http://i.stack.imgur.com/ybxlO.jpg";
}
if (tipo == 3) {
arquivo = "http://i.stack.imgur.com/MRjsF.jpg";
}
document.getElementById("luz").src = arquivo;
}
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Teste Javascript</title>
<script>
function MudaLampada(tipo) {
if (tipo == 1) {
arquivo = "_imagens/lampada-acesa.jpg";
}
if (tipo == 2) {
arquivo = "_imagens/lampada-apagada.jpg";
}
if (tipo == 3) {
arquivo = "_imagens/lampada-quebrada.jpg";
}
document.getElementById("luz").src = arquivo;
}
</script>
</head>
<body>
<h1>Acenda a Lampada</h1>
<img src="_imagens/lampada-apagada.jpg" id="luz" onmousemove="MudaLampada(1)" onmouseout="MudaLampada(2)" onclick="MudaLampada(3)" />
</body>
</html>