我在.net页面上有一些文本框,并希望通过jQuery实现以下内容:如果用户按返回,程序应该使用“好像”他已经使用Tab键,因此选择下一个元素。我尝试了以下代码(还有一些):
<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>
但它只是不工作!缺少一些东西,犯了错误?
这里有一些我使用的链接
here
and here
解决方法
尝试这个:
http://jsbin.com/ofexat
$('.tg').bind('keypress',function(event) {
if(event.which === 13) {
$(this).next().focus();
}
});
或循环版本:http://jsbin.com/ofexat/2