2011-05-29 23 views
8

Tengo el siguiente código en una plantilla de Django:primordial tr onclick

{% for item in items %} 
    <tr onclick="{% url collection:viewitem item_id=item.id %}"> 
    <td>{{ item.name }}</td> 
    <td>{{ item.date }}</td> 
    <td> 
     <button onclick="{% url collection:edititem item_id=item.id %}" type="button">Edit</button> 
     <button onclick="{% url collection:removeitem item_id=item.id %}" type="button">Remove</button> 
    </td> 
    </tr> 
{% endfor %} 

Sin embargo, los eventos de botón onclick no funcionan, debido a que el tr onclick parece anularlo. ¿Cómo puedo evitar que esto suceda?

Respuesta

15

intenta lo siguiente:

<html> 
    <body> 
     <table > 
      <tr onclick="alert('tr');"> 
       <td><input type="button" onclick="event.cancelBubble=true;alert('input');"/></td> 
      </tr> 
     <table> 
    </body> 
</html> 

El event.cancelBubble = true suprimirá el tr evento click

+1

Funciona bien, gracias – synic

0

Usando event.stopPropagation() hará el truco!