0

jQuery Handsontable の最初のフィールドにフォーカス onload を設定する適切な方法は何ですか?

リンクの例は次のとおりです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();
});

大変感謝します!

4

2 に答える 2

2

ご要望ありがとうございます。今、それを行うための公的な方法があります。

ボタンで使用します。

$('#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/

于 2012-06-15T18:47:49.000 に答える
1

これはできません。問題は、handsontable がフォーカス イベントを処理する方法です。クリック ハンドラーをhmtl要素にバインドし、カーソルがテーブル上にあるかどうかをミリ秒ごとに検出します。click()したがって、またはfocus()特定の要素でフォーカスを変更することはできません。

さらに、セキュリティ上の理由から JavaScript を使用してカーソル位置を変更することはできません (また、jQuery はクリックまたはフォーカス イベントをネイティブにトリガーすることはできません) ため、セルのフォーカスを簡単に変更することはできません。選択したテーブル セルを変更するには、handsontable 自体を変更することしかできません。

于 2012-06-13T07:30:53.610 に答える