Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/09/2010, 04:53
Avatar de neodani
neodani
 
Fecha de Ingreso: marzo-2007
Mensajes: 1.811
Antigüedad: 17 años, 1 mes
Puntos: 20
Respuesta: Realizar acción si se pulsa una tecla especifica

Conseguida esa parte...

Código HTML:
Ver original
  1. <title>Trabajando con eventos de teclado en jQuery</title>
  2. <style type="text/css">
  3. #mostrar{
  4. display:none;
  5. background:yellow;
  6. height:100px;
  7. width:200px;
  8. }
  9. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  10. $(document).ready(function(){
  11.    $("html").keypress(function(e){
  12.       e.preventDefault();
  13.       $("#tecla-pulsada").html(e.which + ": " + String.fromCharCode(e.which))
  14.       if (String.fromCharCode(e.which)=='m'){
  15.         $("#mostrar").show("slow");
  16.       }else{
  17.         $("#mostrar").hide("slow")
  18.       }
  19.    });
  20. })
  21. </head>
  22. <h1>Mostrar un texto al pulsar una tecla</h1>
  23. <p id="tecla-pulsada"></p>
  24. <div id="mostrar">Este texto aparecerá cuando se pulse la tecla m</b>
  25. </body>
  26. </html>

Saludos!