2016-10-11 36 views
0

我有一個網站頁面的排序列和加載頁面點擊一排功能加載遊戲僅適用於具有有效的遊戲記錄錶行。表格標題表格行具有列標題而不是遊戲記錄。所以當我點擊一個表頭表格行時,該列會按照它應該排序,但是然後嘗試加載一個遊戲,但它不能。數據表在<a href="http://communitychessclub.com/examine.php" rel="nofollow">http://communitychessclub.com/examine.php</a></p> <p>問題沒有gamescore

$("#cccr").on("click", "tr", function() { 
    window.location.href = 'basic.php?game=' + $(this).attr('game'); 

這可以解決嗎?這是完整的腳本代碼:

$(document).ready(function() { 
    $('#cccr').DataTable({ 
     "createdRow": function(row, data, index) { 
      $(row).attr('game', data.game); 
     }, 
     "search": { 
      "search": "<?php echo ($_GET['player']); ?>" 
     }, 
     "order": [ 
      [0, "asc"] 
     ], 
     "keepConditions": true, 
     "paging": true, 
     "deferRender": false, 
     "oSearch": { 
      "sSearch": "<?php echo ($_GET['player']); ?>" 
     }, 
     "aaSorting": [], 
     "bPaginate": false, 
     "bLengthChange": true, 
     "bFilter": true, 
     "bSort": true, 
     "bInfo": true, 
     "sPaginationType": "numbers", 
     "responsive": true, 
     "bAutoWidth": true, 
     "autoWidth": true, 
     "stateSave": false, 
     "ajax": "assets/games.ajax", 
     "pageLength": 6, 
     "columns": [{ 
      "data": "Date", 
      "width": "7rem", 
     }, { 
      "data": "Event" 
     }, { 
      "data": "ECO" 
     }, { 
      "data": "White" 
     }, { 
      "data": "WhiteElo" 
     }, { 
      "data": "Black" 
     }, { 
      "data": "BlackElo" 
     }, { 
      "data": "Result" 
     }, { 
      "data": "game", 
      visible: false 
     }] 
    }); 

    $("#cccr").on("click", "tr", function() { 
     window.location.href = 'basic.php?game=' + $(this).attr('game'); 
    }); 
}); 

回答

0

試試這個點擊功能只是錶行(tbody tr)不適用於表頭行(thead tr)。實際上,你只需要在tbody元素下單擊tr元素。

$("#cccr").on("click", "tbody tr", function() { 
window.location.href = 'basic.php?game=' + $(this).attr('game');}); 
+0

簡單簡潔而完美! – verlager

0

只需要點擊任何的數據顯示,然後

您可以將事件處理程序附加到每個<td>這樣

$("#cccr").on("click", "td", function() { 
    window.location.href = 'basic.php?game=' + $(this).attr('game'); 

這個小提琴讓你清楚:http://jsfiddle.net/UvjnT/1226/

相關問題