English 中文(简体)
Ignore “enter” key and transport Focus after 5 nature in text Input
原标题:Ignore "enter" key and move Focus after 5 characters in Text Input

我的客户需要扫描一个含有发票号码(5位数)和进入中风的条码。

我需要投入箱,以忽略进入钥匙,并在5个特性之后把重点转移到下一个投入箱。

如果你可以列入一些样本代码,我将不胜感激。 感谢!

最佳回答
$( input[type=text] ).on( keyup , function(e) {
    if (e.which != 27 || e.which != 8) { // check for backspace and delete
        if (e.which != 13) { // ignoring enter
            if (!this.value.replace(/s/g,   ).match(/d/g)) { // checking for digit
                alert( Insert Digit );
                $(this).val(  ); // make the field empty
            } else {
                if (this.value.length > 4) {
                    $(this).next().focus(); // automatically change current input of length 5 digits
                }
            }
        }

    }
});

<

问题回答

如果(event.keyCode=13)return不实,(13是进入钥匙),则使用文本框的基末或基调,并添加该代码。

例如,有2个文本箱(TxtBox1和TxtBox2)

 <input id="TxtBox1" type="submit" onkeypress="if(event.keyCode==13)return false;document.getElementById( TxtBox2 ).focus(); " name="Submit" value="Send" />

一些JQuery:

$( #test ).keydown(function(e) {
if (e.which == 13) {
    if ($(this).val().length == 5) {
        e.preventDefault();
        $( #test2 ).focus();
    }
}
});

体积测试和测试2 是2个文本箱中的id。

不要忽视进入钥匙,而是把它当作你把事情推向一起。 大致如下:

$("#myTextbox").keydown(function(event){
  if(event.keyCode == 13){
  // validate input and move on to the next textbox
  }
});




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签