2017-01-07 34 views
0

我正在嘗試使表中的整行(tr)可點擊。下面是代碼我已經厭倦了,如何使整個<tr>行在laravel中可點擊?

<table class="container"> 
    <thead> 
     <tr> 
     <th><h1>Id</h1></th> 
     <th><h1>Number</h1></th> 
     <th><h1>Type</h1></th> 
     <th><h1>Value</h1></th> 
     </tr> 
    </thead> 
    <tbody> 
     @for ($i = 0; $i < $count; $i++) 
     <tr class="table-tr" data-url="http://www.engineering.us/gena/details.php">  
      <td>{{ $data_array[$i]['id'] }}</td> 
      <td>{{ $data_array[$i]['number'] }}</td> 
      <td>{{ $data_array[$i]['name'] }}</td> 
      <td>{{ $data_array[$i]['value'] }}</td>  
     </tr> 
@endfor  
</tbody> 

`

而且JS腳本,

<script type="text/javascript"> 
    $(function() { 
    $(".container").on("click", "tr[data-url]", function() { 
     window.location = $(this).data("url"); 
    }); 
    }); 
</script> 

這是行不通的。請告訴我們如何做到這一點。

感謝提前:)

+0

'。對( 「點擊」, 「表-TR」)'? –

+0

'$(「table.container tbody tr」)。click(function(){' –

+0

感謝您的建議,它不是在工作的朋友,我在控制檯也沒有任何錯誤 – Haripriya

回答

1

$(function() { 
 
    $('table.container').on("click", "tr.table-tr", function() { 
 
    window.location = $(this).data("url"); 
 
    //alert($(this).data("url")); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table class="container"> 
 
    <thead> 
 
    <tr> 
 
     <th> 
 
     <h1>Id</h1></th> 
 
     <th> 
 
     <h1>Number</h1></th> 
 
     <th> 
 
     <h1>Type</h1></th> 
 
     <th> 
 
     <h1>Value</h1></th> 
 
    </tr> 
 
    </thead> 
 
    <tbody> 
 
    <tr class="table-tr" data-url="http://www.engineering.us/gena/details.php"> 
 
     <td>id</td> 
 
     <td>number</td> 
 
     <td>manash</td> 
 
     <td>28</td> 
 
    </tr> 
 
    </tbody> 
 
</table>

+0

它的工作..非常感謝:) – Haripriya

+0

@Haripriya米很高興它的工作 – msonowal