我發現我的第一個答案how to make a whole row in a table clickable as a link?,但現在出現了一個新問題:如何排除在JavaScript中點擊一行中的<a>標籤?
使用
<tbody>
<tr class='clickable-row' data-href='url://link-for-first-row/'>
<td>Blah Blah</td>
<td>1234567</td>
<td>£158,000</td>
</tr>
<tr class='clickable-row' data-href='url://some-other-link/'>
<td>More money</td>
<td>1234567</td>
<td><a href="url://somewhere-else-than-the-row">£800,000</a></td>
</tr>
</tbody>
和
jQuery(document).ready(function($) {
$(".clickable-row").click(function() {
window.document.location = $(this).data("href");
});
});
使我陷入困境與最後一個環節爲「 url:// somewhere-else-the-row',特別是當我使用method =「delete」屬性的鏈接時,「你確定嗎?」彈出,但是,我不想讓window.location
運行。那麼,如何從window.document.location
參考中排除<a>
元素上的單擊?
感謝這兩者,我更喜歡這個解決方案,因爲我在rails上使用ruby,並且我可以簡單地使用link_to helper。我使用<%= link_to glyph('remove'),admin_person_path(admin_person),方法:: delete,data:{confirm:'你確定嗎? }%>爲其中一個鏈接,所以這個解決方案是easyer使用。 – Martin