<!DOCTYPE html>
<html>
<body>
<h2>What Can JavaScript Do?</h2>
<p>JavaScript can change HTML attribute values.</p>
<p>In this case JavaScript changes the value of the src (source) attribute of an image.</p>
<img id="myImage" src="pic_bulboff.gif" style="width:100px" onclick="lampada()" onmouseover="document.getElementById('myImage').style.cursor='pointer'">
<script>
lamp=true;
function lampada(){
if(lamp){
lamp=false;
document.getElementById('myImage').src='pic_bulbon.gif'
} else {
lamp=true;
document.getElementById('myImage').src='pic_bulboff.gif'
}
}
</script>
</body>
</html>
ou
<script>
lamp=true;
function lampada(){
if(lamp){
lamp=false;
light='pic_bulbon.gif';
} else {
lamp=true;
light ='pic_bulboff.gif';
}
document.getElementById('myImage').src=light;}
</script>
Sem comentários:
Enviar um comentário