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条)

报告相同问题?

悬赏问题

  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。