javascript - 如何使整个 <tr> 行在 laravel 中可点击?

标签 javascript php 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>

关于javascript - 如何使整个 <tr> 行在 laravel 中可点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41520202/

相关文章:

javascript - ES6 生成器如何辅助非阻塞代码?

php - Laravel 保存关系

php - Laravel无法解析的依赖项,在类GuzzleHttp\Psr7\Request中解析[Parameter#0 [<required> $ method]]

php - 你如何改变 Laravel 通知的排序

javascript - JSON 数据 if/else 解析

php - 向程序员寻求帮助

javascript - 如何在我的页面中加载所有图像后运行 jQuery 代码?

php - 在 Mac 上通过 PHP 中的 scandir 访问外部 NAS/Volume

javascript - ajax文件下载 : progress event, 进行下载

php - 如何恢复 netbeans 的默认行为?