我正在尝试检测表td元素中链接的点击,点击时不会引发警告
我在我的资产中添加了一个js文件,并在我的application.js
中添加了requireapplication.js
...
//= require albums
albums.js
$(function() {
$("#owners tr td a").click(function() {
return alert(clicked);
});
});
html在模态窗口中
<div class="modal-body-content" id="myModalBody" style="display: block;">
<div id="owner_list">
<div class="pagination pull-right">
<ul class="pagination pagination-sd">
<li class="page active">
<a data-remote="true" href="#">1</a>
</li>
<li class="page">
<a data-remote="true" href="/backoffice/users.js?locale=fr&page=2" rel="next">2</a>
</li>
<li class="next pagination">
<a data-remote="true" href="/backoffice/users.js?locale=fr&page=2" rel="next">suiv.</a>
</li>
</ul>
</div>
<div class="table_responsive">
<table class="container table" id="owners">
<thead>
<tr>
<td>Adresse courriel</td>
<td>Identifiant</td>
<td>Prénom</td>
<td>Nom</td>
</tr>
</thead>
<tbody>
<tr class="clear">
<td><a href="#">active.memory@example.com</a></td>
<td><a href="#">active_memory</a></td>
<td>Active</td>
<td>Memory</td>
</tr>
<tr class="clear">
<td><a href="#">albert.camus@example.com</a></td>
<td><a href="#">albert</a></td>
<td>n/a</td>
<td>n/a</td>
</tr>
<tr class="clear">
<td><a href="#">arthur.rubinstein@example.com</a></td>
<td><a href="#">arthur</a></td>
<td>n/a</td>
<td>n/a</td>
</tr>
<tr class="clear">
<td><a href="#">debbie.kind@example.com</a></td>
<td><a href="#">debbie</a></td>
<td>Debbie</td>
<td>Elkind</td>
</tr>
<tr class="clear">
<td><a href="#">sergio.mendez@example.com</a></td>
<td><a href="#">sergio</a></td>
<td>n/a</td>
<td>n/a</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
我做错了什么?
答案 0 :(得分:0)
我修改了javascript,它现在运行得非常好:
$(document).on('click', '#owners tr td a', function(e) {
alert('clicked');
e.preventDefault();
return e.stopPropagation();
});