douyu9433 2015-05-30 05:06
浏览 40
已采纳

数据表链接在第一页后停止工作

I have a datatable with a data-href inside to create a link to a forum page, My issue lies in the place that my datatable link works great on page one, but when I go to page two I can no longer follow the link,but it still has all the data of a link when I inspect element. My JS and Style for the link within the datatable

<style>
        tr.clickable-row { cursor: pointer; }
        tr.clickable-row:hover { background-color:#F0F8FF;}
        </style>
        <script>
        jQuery(document).ready(function($) {
    $(".clickable-row").on('click',$('.clickable-row'),function() {
        window.document.location = $(this).data("href");
    });
});
</script>

All rows are called upon by MySQL tables to populate the data and are pulled correctly.

echo "<tr class='clickable-row' data-href='viewPage.php?id=".inv_forum_page()."&forum=".$forum['id']."'>
    <td>".$authorname."</td><td>".$posttype."".$forum['subject']."</td><td>".$forum['replies']."</td><td>".$forum['views']."</td>
    </tr>";

I don't feel like posting the entire function as it's quite a bit of code when I don't believe it's the issue since it works on page one I believe it has to do with my Jquery, but if you want to look at the function itself it is on github under https://github.com/Doxramos/Invontrol/blob/master/plugins/inv_forum/functions.php line 75-123 I read on delegated events and I believe that that's scripted correctly, s I'm not sure what the issue is at this point.

  • 写回答

2条回答 默认 最新

  • douchenzhan3050 2015-05-30 05:47
    关注

    use below code

    your problem is called Event Delegation.

    Event delegation allows us to attach a single event listener, to a parent element, that will fire for all descendants matching a selector, whether those descendants exist now or are added in the future.

    <script>
        jQuery(document).ready(function($) {
           $(document).on('click','.clickable-row',function() {
              window.document.location = $(this).data("href");
           });
        });
    </script>
    

    if you call click event every time new page call use below code.

    <script>
        jQuery(document).ready(function($) {
           $(document).off('click').on('click','.clickable-row',function() {
              window.document.location = $(this).data("href");
           });
        });
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)