通过按Enter键,移动到ASP.Net中的下一个文本框. [英] By Pressing Enter key move to next Textbox in ASP.Net

查看:106
本文介绍了通过按Enter键,移动到ASP.Net中的下一个文本框.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文本框和一个Button控件.....在第一个TextBox中,按Enter键将移至下一个文本框(条形码),而当我在条形码文本框中按Enter时,它将触发按钮单击事件……直到确定....

但是,即使在条形码文本框"中输入内容后,单击触发"按钮后也会发生什么,它又回到了第一个文本框上……......但是我希望它保留在同一条形码文本框"中以扫描更多的条形码. /p>

代码在下面.

 <script type="text/javascript" 
        src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js">
    </script>

<Head>
<script type="text/javascript">
        $(function() {
            $('input:text:first').focus();
            var $inp = $('input:text');
            $inp.bind('keydown', function(e) {
                //var key = (e.keyCode ? e.keyCode : e.charCode);
                var key = e.which;
                if (key == 13) {
                    e.preventDefault();
                    var nxtIdx = $inp.index(this) + 1;
                    $(":input:text:eq(" + nxtIdx + ")").focus();
                }                
            });
        });
    </script>

</Head>

解决方案

您正在为每个文本框处理keydown.

您需要修改选择器,使其仅处理第一个文本框的keydown.

I have two textboxes and one Button control.....In first TextBox when press enter key moves to next textbox(Barcode) and when i press enter in barcode textbox it fires the button click event......till that its ok....

But what happening after fireing the Button click even on enter in Barcode Textbox its going back to focus on first textbox.........But i want this to stay in same Barcode TextBox to scan more barcodes.

The code is below.

 <script type="text/javascript" 
        src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js">
    </script>

<Head>
<script type="text/javascript">
        $(function() {
            $('input:text:first').focus();
            var $inp = $('input:text');
            $inp.bind('keydown', function(e) {
                //var key = (e.keyCode ? e.keyCode : e.charCode);
                var key = e.which;
                if (key == 13) {
                    e.preventDefault();
                    var nxtIdx = $inp.index(this) + 1;
                    $(":input:text:eq(" + nxtIdx + ")").focus();
                }                
            });
        });
    </script>

</Head>

解决方案

You're handling keydown for every textbox.

You need to modify your selector to only handle keydown for the first textbox.

这篇关于通过按Enter键,移动到ASP.Net中的下一个文本框.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆