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 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)