简体   繁体   中英

How to make entire <tr> row clickable in laravel?

I am trying to make whole row (tr) clickable in table. Here is the code I have tired,

<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>

`

And the JS Script,

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

It is not working. Please tell how can we do this.

Thanks in advance :)

 $(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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM