如何 Onload() 将焦点设置为 jQuery Handsontable

How to Onload() set focus to jQuery Handsontable

本文关键字:设置 jQuery Handsontable 焦点 Onload 如何      更新时间:2023-09-26

jQuery Handsontable中将焦点加载设置为第一个字段的正确方法是什么?

这是示例链接 http://jsfiddle.net/4kvMq/4/

$(function () {
  $(window).load(function () {
    $('#example10grid table tbody tr td:first-child').focus();
  });
});

甚至尝试手动设置焦点,但没有运气!

$('#btnGo').click(function() {
    $(".dataTable table tbody tr td:first-child").focus();
});

非常感谢!

感谢您的请求。现在有一种公共方法可以做到这一点。

在按钮上使用它:

$('#btnGo').click(function(event) {
  setTimeout(function() {
      //timeout is needed because Handsontable normally deselects 
      //current cell when you click outside the table
      $("#example10grid").handsontable("selectCell", 0, 0);
  }, 10);
});

或者 DOM 就绪:

$(function() {
  setTimeout(function() { 
      //timeout is needed because Handsontable normally deselects 
      //current cell when you click outside the table
      $("#example10grid").handsontable("selectCell", 0, 0);
  }, 10);
});

现场示例:http://jsfiddle.net/warpech/4kvMq/35/

你不能这样做。问题在于可动手处理焦点事件的方式。它将单击处理程序绑定到 hmtl 元素,并每毫秒检测一次光标是否在表上。因此,不能通过特定元素上的click()focus()来更改焦点。

此外,由于出于安全原因,您无法使用 JavaScript 更改光标位置(并且 jQuery 无法在本地触发单击或焦点事件),因此您无法轻松更改单元格上的焦点。只能修改可动手表本身以更改选定的表格单元格。