【问题标题】:dataTables table row not linking to URLdataTables 表行未链接到 URL
【发布时间】:2014-11-14 20:20:19
【问题描述】:

我在 http://communitychessclub.com/test.php 使用 dataTables 并获取如下所示的 ajax 数据:

{
"data": [
{
"game": "5086",
"date": "09/02/2013",
"event": "135th NYS Ch.",
"eco": "B08",
"white": "Jones, Igor",
"white_rating": "2393",
"black": "Smith, Efim",
"black_rating": "2268"
},

我有这个不完整的代码,并希望使表格行可点击,以便点击链接到'basic.php?game="data:game"'

**$("#cccr tbody").delegate("tr", "click", function(e) {
//rest of the code here
});**

我要问的是什么代码替换了“//这里的其余代码”?是否与:window.location.href 有关?

【问题讨论】:

    标签: datatables


    【解决方案1】:

    您就快到了,但不需要委托人:

    $(document).ready(function() {
        var table = $("#example").DataTable();
        $('#example tbody').on('click', 'tr', function(){
            var row_date = table.row(this).data();
            console.log(row_date[0]);
            window.location = "http://www.google.com/search?q"+row_date[0];
        });
    });
    

    例如 here,它不会更改 URI,因为它会尝试更改 iframe 的来源……但在您的用例中可能不是问题。

    【讨论】:

      猜你喜欢
      • 2018-05-02
      • 1970-01-01
      • 2011-11-23
      • 2022-01-18
      • 1970-01-01
      • 2014-06-27
      • 1970-01-01
      • 2014-10-07
      • 1970-01-01
      相关资源
      最近更新 更多