繁体   English   中英

onclick事件在链接上不起作用

[英]onclick event is not working on Link

我在数据表中启用了服务器端处理。 我将以下代码用于数据表:

<script type="text/javascript">
$(document).ready(function() {
   var table = $('#FullDataDisplay').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": "server_processing.php",
    "aoColumnDefs": [            
 {
   "aTargets": [ 2 ], // Column to target
   "mRender": function ( data, type, full ) {
     return '<a id=' + full[0] + ' class="edit-link" href="#" title="Edit">' + data + '</a>';
   }
 }
 ]
 } );
} );
</script>

这正确地返回了传递给我的crud.js脚本所需的链接,内容如下:

/* Get Edit ID  */
    $(".edit-link").click(function()
    {
            var id = $(this).attr("id");
            var edit_id = id;
            {
                    $(".content-loader").fadeOut('slow', function()
                     {
                            $(".content-loader").fadeIn('slow');
                            $(".content-loader").load('edit_form.php?edit_id='+edit_id);
                            $("#btn-add").hide();
                            $("#btn-view").show();
                    });
            }
            return false;
    });
    /* Get Edit ID  */

问题是,当单击链接时,什么也没有发生。

由于您是通过AJAX动态加载内容,因此需要使用$(document)

/* Get Edit ID  */
$(document).on('click',".edit-link",function() {
    var id = $(this).attr("id");
    var edit_id = id; {
        $(".content-loader").fadeOut('slow', function() {
            $(".content-loader").fadeIn('slow');
            $(".content-loader").load('edit_form.php?edit_id=' + edit_id);
            $("#btn-add").hide();
            $("#btn-view").show();
        });
    }
    return false;
});
/* Get Edit ID  */

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM