gpt4 book ai didi

jquery - 表中可编辑字段之间的 Tab 键切换

转载 作者:行者123 更新时间:2023-12-01 00:01:46 25 4
gpt4 key购买 nike

我正在使用这里的代码 http://www.korvus.com/blog/geek/making-the-tab-key-work-with-jeditable-fields/在 jeditable 字段之间进行制表符工作,如果这些字段是独立的,则可以正常工作。但是,我需要将我的字段放在表中,并且 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>

提前致谢

最佳答案

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

关于jquery - 表中可编辑字段之间的 Tab 键切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3890775/

25 4 0
文章推荐: jquery - ASP.Net -- jQuery 填充列表后