【问题标题】:onclick not working with the pagination on jQueryonclick 不适用于 jQuery 上的分页
【发布时间】:2014-09-15 14:18:08
【问题描述】:

当我们点击元素时,我们有带有分页的表格,第一个元素有添加侦听器,下一页没有添加侦听器。点击不适用于表格。 这是我的代码,请帮助我。 这是我的桌子

<table id="data_table">
    <thead>
        <tr>
            <th>Column 1</th>
            <th>Column 2</th>
        </tr>
    </thead>
    <tbody>
        <tr id="hello">
            <td>Row 1 Label</td>
            <td>
                <select class="user-selection">
                    <option>Row 1 Data</option>
                </select>
            </td>
        </tr>
        <tr id="hello">
            <td>Row 2 Label</td>
            <td>
                <select class="user-selection">
                    <option>Row 2 Data</option>
                </select>
            </td>
        </tr>
        <tr id="hello">
            <td>Row 3 Label</td>
            <td>
                <select class="user-selection">
                    <option>Row 3 Data</option>
                </select>
            </td>
        </tr>
        <tr id="hello">
            <td>Row 4 Label</td>
            <td>
                <select class="user-selection">
                    <option>Row 4 Data</option>
                </select>
            </td>
        </tr>
        <tr id="hello">
            <td>Row 5 Label</td>
            <td>
                <select class="user-selection">
                    <option>Row 5 Data</option>
                </select>
            </td>
        </tr>
        <tr id="hello">
            <td>Row 6 Label</td>
            <td>
                <select class="user-selection">
                    <option>Row 6 Data</option>
                </select>
            </td>
        </tr>
        <tr id="hello">
            <td>Row 7 Label</td>
            <td>
                <select class="user-selection">
                    <option>Row 7 Data</option>
                </select>
            </td>
        </tr>
        <tr id="hello">
            <td>Row 8 Data 1</td>
            <td>
                <select class="user-selection">
                    <option>Row 8 Data</option>
                </select>
            </td>
        </tr>
        <tr id="hello">
            <td>Row 9 Data 1</td>
            <td>
                <select class="user-selection">
                    <option>Row 9 Data</option>
                </select>
            </td>
        </tr>
    </tbody>
</table>

这是我的 jquery

$(function () {
    var dataTable = $('#data_table').DataTable({
        "pageLength": 6
    });

    var allDropDowns = dataTable.$('select');
    $.each(allDropDowns, function (index, dropdown) {
        console.log(dropdown.value);
    })


});


$(document).ready(function(){
    $("tr#hello").click(function() {
        alert("hello");
    });  
});

Click 在第一个分页上工作正常,在其他分页上不工作。

【问题讨论】:

  • @vikrantsingh 能否提供 jsfiddle 示例。
  • id 应该是唯一的。你所有的行都有id="hello"。请先更改它。
  • @vikrantsingh 我收到此错误请帮助我。TypeError: $(...).on 不是函数 $('#example').on("click","tr#对话确认",function() {
  • 添加示例 fiddle 或更新您的代码。您在哪里得到 $(...).on is not a function 错误

标签: javascript jquery ajax pagination


【解决方案1】:

使用 jQuery On 方法。

像这样更改代码:

  $(document).on('click','tr#hello', function() {
    alert("hello");
}); 

【讨论】:

  • 你能提供这个的替代品吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-28
  • 2013-12-30
  • 2015-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-07
相关资源
最近更新 更多