Disparo un evento de clic a través de cuestiones (event.button! = 0)

  • RockmanTV
  • Proficient
  • Proficient
  • No Avatar
  • Registrado: Oct 12, 2004
  • Mensajes: 348
  • Status: Offline

Nota Abril 8th, 2010, 12:15 pm

Tengo un objeto que tiene un evento de clic Im tratando de provocar. Sin embargo, en el evento click tengo el siguiente if: if (event.button! = 0) (return true;)

Esta declaración permite que si hace clic en la derecha para ir a través y activar sino que también me impide poner en marcha el evento. Cualquier ideas sobre cómo evitar esto? Si elimino la declaración si del todo lo que haga clic en la primera función funciona como está previsto.

Heres mi código de ejemplo con sede fuera de el ejemplo del disparador de eventos jQuery 1:
Código: [ Select ]
<!DOCTYPE html>
<html>
<head>
 <style>

button { margin:10px; }
div { color:blue; font-weight:bold; }
span { color:red; }
</style>
 <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<a href="#" class="quoteLink">Button #1</a>
<a href="#" class="quotelink2">Button #2</a>

<div><span>0</span> button #1 clicks.</div>

<div><span>0</span> button #2 clicks.</div>
<script>
$(".quoteLink").live("click", function(event){
    if(event.button != 0){return true;}
    update($("span:first"));
});



$(".quotelink2").live("mouseover", function(event){
 $(".quoteLink").trigger('click');
    update($("span:last"));
});

function update(j) {
var n = parseInt(j.text(), 10);
j.text(n + 1);
}
</script>
</body>
</html>
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.  <style>
  5. button { margin:10px; }
  6. div { color:blue; font-weight:bold; }
  7. span { color:red; }
  8. </style>
  9.  <script src="http://code.jquery.com/jquery-latest.js"></script>
  10. </head>
  11. <body>
  12. <a href="#" class="quoteLink">Button #1</a>
  13. <a href="#" class="quotelink2">Button #2</a>
  14. <div><span>0</span> button #1 clicks.</div>
  15. <div><span>0</span> button #2 clicks.</div>
  16. <script>
  17. $(".quoteLink").live("click", function(event){
  18.     if(event.button != 0){return true;}
  19.     update($("span:first"));
  20. });
  21. $(".quotelink2").live("mouseover", function(event){
  22.  $(".quoteLink").trigger('click');
  23.     update($("span:last"));
  24. });
  25. function update(j) {
  26. var n = parseInt(j.text(), 10);
  27. j.text(n + 1);
  28. }
  29. </script>
  30. </body>
  31. </html>
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Abril 8th, 2010, 12:15 pm

  • RockmanTV
  • Proficient
  • Proficient
  • No Avatar
  • Registrado: Oct 12, 2004
  • Mensajes: 348
  • Status: Offline

Nota Abril 8th, 2010, 1:15 pm

Para aquellos de ustedes que se pegan con esta cuestión (que encontré la respuesta en otro lugar), en esta situación estableciendo el gatillo para arriba como esto debería funcionar:

$ (". QuoteLink"). Gatillo ((type: "click", un botón: 0));

Espero que ayude!

Publicar Información

  • Total de mensajes en este tema: 2 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 266 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC