Ver Mensaje Individual
  #2 (permalink)  
Antiguo 18/03/2011, 19:55
InKarC
 
Fecha de Ingreso: noviembre-2005
Mensajes: 426
Antigüedad: 18 años, 5 meses
Puntos: 87
Respuesta: Seleccionar el ID de una tabla utilizando eventos del mouse

Para fritar un huevo necesitas una cacerola, pues bueno, para hacer algo interesante en javascript sin volarte los sesos en el proceso necesitas un framework.

En jQuery eso seria simplemente:

Código:
$(document).ready(function(){
$("td").click(function(){
alert(this.id)	;
})
})

Aqui una prueba funcionando con este código (solo es copiar, pegar y funca)

Código:
<!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=utf-8" />
<title>Documento sin título</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" >

$(document).ready(function(){
$("td").click(function(){
alert(this.id)	;
})
})
</script> 
</head>

<body>

<table width="640" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td id="celda_gantz">Gantz</td>
    <td id="celda_evangelio">Evangelion</td>
    <td id="celda_dbz">Dragon Ball Z</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td id="celda_samuraix">Samurai X</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

</body>
</html>