admin管理员组文章数量:1316980
I am trying to create a form where, if you press enter key on the serial column, the cell below bees selected. Can someone please solve the correct jquery formula for this task?
I am trying
$('.serial').keypress(function(e) {
console.log(this);
if (e.which == 13) {
$(this).nextAll('#serial').first().focus();
e.preventDefault();
}
});
/
I am trying to create a form where, if you press enter key on the serial column, the cell below bees selected. Can someone please solve the correct jquery formula for this task?
I am trying
$('.serial').keypress(function(e) {
console.log(this);
if (e.which == 13) {
$(this).nextAll('#serial').first().focus();
e.preventDefault();
}
});
http://jsfiddle/tYFcH/4/
Share Improve this question edited Jan 23, 2013 at 1:29 Jeff 12.8k5 gold badges35 silver badges61 bronze badges asked Jan 23, 2013 at 1:20 user2002232user2002232 231 silver badge5 bronze badges 1-
1
'#serial' !== '.serial'
– epascarello Commented Jan 23, 2013 at 1:23
3 Answers
Reset to default 5Assuming you want to move to the cell below when hitting enter in any input, use this:
$('table input').keypress(function(e) {
if (e.keyCode == 13) {
var $this = $(this),
index = $this.closest('td').index();
$this.closest('tr').next().find('td').eq(index).find('input').focus();
e.preventDefault();
}
});
Here's your fiddle: http://jsfiddle/tYFcH/13/
$('.serial').keypress(function(e) {
console.log(this);
if (e.which == 13) {
$(this).closest('tr').next().find('input.serial').focus();
e.preventDefault();
}
});
http://jsfiddle/tYFcH/6/
The next-in-dom plugin was written for this purpose. Disclaimer: I wrote it
http://techfoobar./jquery-next-in-dom/
$('.serial').keypress(function(e) {
if (e.which == 13) {
$(this).nextInDOM('.serial').focus();
}
});
本文标签: javascriptOn enter key move to next cell down in a tableStack Overflow
版权声明:本文标题:javascript - On enter key move to next cell down in a table - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742017099a2413973.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论