Jquery:在表头和tfoot中附加所有锚点击事件

时间:2016-01-13 13:17:23

标签: jquery

这是我的样本表。我只是在这里不包括tfoot html。

<table class="test-table">
<thead>
<tr class="webgrid-header">

    <th scope="col">
    <a href="http://localhost:13562/page1">ID</a></th>

    <th scope="col">
    <a href="http://localhost:13562/page1">First Name</a></th>
    </tr>
    </thead>
    </table>

我使用了这个jquery代码,但没有运气。

$(document).on('click', '.webgrid-header .webgrid-footer a', function () {
    alert('Click on link');
});

我犯了错误。

2 个答案:

答案 0 :(得分:2)

你应该像下面这样做。使用.webgrid-header a, .webgrid-footer a代替.webgrid-header .webgrid-footer a

$(document).on('click', '.webgrid-header a, .webgrid-footer a', function (event) {
    event.preventDefault();
    alert('Click on link');
});

答案 1 :(得分:0)

使用.webgrid-header a, .webgrid-footer a代替.webgrid-header .webgrid-footer a

检查multiple-selector

$(document).on('click', '.webgrid-header a, .webgrid-footer a', function () {
    alert('Click on link');
});