【问题标题】:tabbing between jeditable fields in a table在表中的可编辑字段之间切换
【发布时间】:2010-10-08 13:08:23
【问题描述】:

我正在使用http://www.korvus.com/blog/geek/making-the-tab-key-work-with-jeditable-fields/ 此处的代码在可编辑字段之间切换,如果这些字段是独立的,则可以正常工作。但是我需要将我的字段放在一个表中,并且 tab 键唯一起作用的时间是从最后一个字段到第一个字段,当然我需要它从第一个字段到下一个字段等等......

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

提前致谢

【问题讨论】:

标签: jquery jeditable


【解决方案1】:

我认为问题在于您的输入字段不是彼此的直接兄弟,因此“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
};
}); 

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2020-12-12
  • 2023-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多