2017-01-07 2 views
0

Я пытаюсь сделать целую строку (tr) в таблице. Вот код, я устал,Как сделать целое <tr> row clickable в 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

'.он ("щелчок", ".table-тр")'? –

+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 m рад, что он сработал – msonowal

Смежные вопросы