duannuo7878
2014-09-22 21:56 阅读 79

字符串中的Echo JQuery变量

I've searched around and for something so easy I can't find a solution that works for me. I have a table object with an ID. I'm using JQuery to grab the ID on the clicked object and want to pass it my datasource, but i'm not able to. Can someone help me out?

HTML:

<a href="#" data-toggle="modal" data-target="#clusterpulse" id="cluster1">cluster1</a>

JavaScript:

<script>
$("table").delegate("a", "click", function() {
    id2=$(this).attr('id');
}); 

$('#cluster_pulse_table').dataTable( {
      "bprocessing": true,
      "bserverSide": true,
      "sAjaxSource": "../scripts/cluster_pulse.php?val=" + id2,
} );
</script>  
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongwei9771 dongwei9771 2014-09-22 22:02

    Well you can change delegate with on

    $("table").on("click", "a", function() {
        var id2 = $(this).attr('id');
    
        $('#cluster_pulse_table').dataTable( {
           "bprocessing": true,
           "bserverSide": true,
           "sAjaxSource": "../scripts/cluster_pulse.php?val=" + id2,
        });
    
    }); 
    

    And you need to call dataTable after you have the id2 value. As you had it dataTable was called without it, so that could be one place for an error.

    点赞 评论 复制链接分享

相关推荐