4

ここhttp://www.korvus.com/blog/geek/making-the-tab-key-work-with-jeditable-fields/のコードを使用して、jeditableフィールド間のタブを機能させています。それ自体は正常に機能します。ただし、フィールドをテーブルに配置する必要があります。タブキーが機能するのは、最後のフィールドから最初のフィールドへのタブ移動だけです。もちろん、最初から次のフィールドへのタブ移動なども必要です...

$('div.edit').bind('keydown', function(evt) {
if(evt.keyCode==9) {
    $(this).find("input").blur();
    var nextBox='';

     if ($("div.edit").index(this) == ($("div.edit").length-1)) {
           nextBox=$("div.edit:first");         //last box, go to first
       } else {
            nextBox=$(this).next("div.edit");    //Next box in line
       }
    $(nextBox).click();  //Go to assigned next box
    return false;           //Suppress normal tab
};
});

テーブルは次のようにフォーマットされています

<table>

<tr>
  <td class='leftcolumn'>
     <strong>Firstname:</strong>
  </td>
  <td>
     <div class='edit' id='firstname'><?=$userdetail['firstname']?></div>
  </td>
</tr>

<tr>
  <td class='leftcolumn'>
     <strong>Lastname:</strong>
  </td>
  <td>
     <div class='edit' id='lastname'><?=$userdetail['lastname']?></div>
  </td>
</tr>
</table>

前もって感謝します

4

1 に答える 1

8

問題は、入力フィールドが互いに直接の兄弟ではないため、「next()」が失敗していることだと思います。私はこれがうまくいくと思います:

$('div.edit').bind('keydown', function(evt) {
if(evt.keyCode==9) {
    var nextBox='';
    var currentBoxIndex=$("div.edit").index(this);
     if (currentBoxIndex == ($("div.edit").length-1)) {
           nextBox=$("div.edit:first");         //last box, go to first
       } else {
            nextBox=$("div.edit").eq(currentBoxIndex+1);    //Next box in line
       }
    $(this).find("input").blur();
    $(nextBox).click();  //Go to assigned next box
    return false;           //Suppress normal tab
};
}); 
于 2011-09-20T17:22:31.070 に答える