Fijate así:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
</head>
<body>
<div id="losBotones0" style=" width:100px; cursor:pointer">a</div>
<div id="losBotones1" style=" width:100px; cursor:pointer">b</div>
<div id="losBotones2" style=" width:100px; cursor:pointer">c</div>
<img name="imgSrc" src="1.jpg" width="50" />
<div id="algo"></div>
<script>
var losBotones=['losBotones0','losBotones1','losBotones2'];
var misImagenes=['1.jpg','2.jpg','3.jpg'];
var texto=['uno','dos','tres'];
var dTexto=document.getElementById('algo');
for(var i=0;i<3;i++){
var actual=document.getElementById(losBotones[i]);
dTexto.innerHTML+=losBotones[i]+'<br />';
(function(){
var ii=i;
actual.onclick=function(){
document.imgSrc.src = misImagenes[ii];
dTexto.innerHTML = texto[ii];
}
})();
}
</script>
</body>
</html>
O así:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
</head>
<body>
<div id="losBotones0" style=" width:100px; cursor:pointer">a</div>
<div id="losBotones1" style=" width:100px; cursor:pointer">b</div>
<div id="losBotones2" style=" width:100px; cursor:pointer">c</div>
<img name="imgSrc" src="1.jpg" width="50" />
<div id="algo"></div>
<script>
var losBotones=['losBotones0','losBotones1','losBotones2'];
var misImagenes=['1.jpg','2.jpg','3.jpg'];
var texto=['uno','dos','tres'];
var dTexto=document.getElementById('algo');
for(var i=0;i<3;i++){
var actual=document.getElementById(losBotones[i]);
dTexto.innerHTML+=losBotones[i]+'<br />';
actual.i=i
actual.onclick=function(){
document.imgSrc.src = misImagenes[this.i];
dTexto.innerHTML = texto[this.i];
}
}
</script>
</body>
</html>
Adicionalmente te recomiendo que leas esto:
http://blog.scriptia.net/articulos/2...esperados.html