使用jQuery模拟按下Tab键 [英] Simulate pressing tab key with jQuery
本文介绍了使用jQuery模拟按下Tab键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在.net页上有一些文本框,并希望通过jQuery实现以下功能:如果用户按return键,则程序应表现为好像"他使用了tab键,因此选择了下一个元素.我尝试了以下代码(还有更多):
I have some textboxes on a .net-page and want to achieve the following with jQuery: if the user presses return, the program should behave "as if" he had used the tab key, thus, selecting the next element. I tried the following code (and some more):
<script type="text/javascript">
jQuery(document).ready(function () {
$('.tb').keypress(function (e) {
if (e.keyCode == 13)
{
$(this).trigger("keydown", [9]);
alert("return pressed");
}
});
});
<asp:TextBox ID="TextBox1" runat="server" CssClass="tb"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" CssClass="tb"></asp:TextBox>
但是它根本不起作用!缺少东西,犯错了吗?
but it just does not work! Missing something, making a mistake?
这是我使用的一些链接
推荐答案
尝试一下:
$('.tg').bind('keypress', function(event) {
if(event.which === 13) {
$(this).next().focus();
}
});
或循环版本: http://jsbin.com/ofexat/2
这篇关于使用jQuery模拟按下Tab键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文