簡體   English   中英

如何制作整張 <tr> 在laravel中點擊行?

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

我試圖使整個行(tr)在表中可單擊。 這是我討厭的代碼,

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

它不起作用。 請告訴我們如何做到這一點。

提前致謝 :)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM