syn*_*nic 9 html javascript django-templates
我在django模板中有以下代码:
{% 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 %}
Run Code Online (Sandbox Code Playgroud)
但是,按钮onclick事件不起作用,因为tr onclick似乎覆盖它.我怎样才能防止这种情况发生?
Mar*_*ark 18
请尝试以下方法:
<html>
<body>
<table >
<tr onclick="alert('tr');">
<td><input type="button" onclick="event.cancelBubble=true;alert('input');"/></td>
</tr>
<table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
该event.cancelBubble =真会抑制TR click事件
| 归档时间: |
|
| 查看次数: |
4533 次 |
| 最近记录: |