在 javascript 中将焦点设置在 dataTable 上

Set focus on dataTable in javascript

本文关键字:dataTable 设置 javascript 焦点      更新时间:2023-09-26
<table id="table-dispatch" class="display data-table" cellspacing="0" width="100%"  onclick="showrequestmap()">
        <thead>
          <tr>
            <th> ID </th>
            <th> Status </th>
            <th> Client </th>
            <th> Client Phone Number </th>
            <th> Dispatch Date </th>
            <th> Driver </th>
            <th> Distance </th>
            <th> Current Location </th>
            <th> Estimated Fare </th>
            <th> Action </th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>5</td>
            <td> Waiting for pickup </td>
            <td> Raj </td>
            <td> 85115 </td>
            <td> Apr 18, 2016 7:07 PM </td>
            <td> tushar patel </td>
            <td> NaN </td>
            <td> Thaltej, Ahmedabad, Gujarat 380054, India </td>
            <td> 0$ </td>
            <td> action </td>
          </tr>
        </tbody>
      </table>
    </div>

这是我的数据表。以及如何在 JavaScript 中的 DataTable 上设置焦点方法。

$(document).ready(function(){
  $("#table-dispatch").focus(function() {  
  });
});

这是我的JavaScript代码.我尝试将焦点方法放在DataTable Id上。但它不起作用。那么我怎样才能在数据表上集中使用方法。请给我解决方案。以及如何在单击方法之前优先考虑焦点方法。

看看这些代码,它不是悬停,但我通过 mouseover(( 函数实现了相同的功能。

js小提琴 : https://jsfiddle.net/eua98tqa/12/

j查询:

$('#table-dispatch').mouseover(function(){
  $(this).css('background-color','#ddd');
}).mouseout(function(){
  $(this).css('background-color','#bbb');
});