Javascript jQuery-在键向上时转到下一个输入字段
我现在正忙着把13个输入字段的结果合并成一个变量,我必须把它分成13个,因为我需要添加一个块效果,就像你在现实世界中的许多表单上看到的那样。每个块的限制是一个,我需要找到一个,这样当你插入一个数字时,它会进入下一个字段,直到所有字段都被填满,然后一个验证函数就会启动 以下是html:Javascript jQuery-在键向上时转到下一个输入字段,javascript,jquery,Javascript,Jquery,我现在正忙着把13个输入字段的结果合并成一个变量,我必须把它分成13个,因为我需要添加一个块效果,就像你在现实世界中的许多表单上看到的那样。每个块的限制是一个,我需要找到一个,这样当你插入一个数字时,它会进入下一个字段,直到所有字段都被填满,然后一个验证函数就会启动 以下是html: <div id="error"></div> <form id="idCheck"> <input class="id" id="idnumber1" maxlength
<div id="error"></div>
<form id="idCheck">
<input class="id" id="idnumber1" maxlength="1" />
<input class="id" id="idnumber2" maxlength="1" />
<input class="id" id="idnumber3" maxlength="1" />
<input class="id" id="idnumber4" maxlength="1" />
<input class="id" id="idnumber5" maxlength="1" />
<input class="id" id="idnumber6" maxlength="1" />
<input class="id" id="idnumber7" maxlength="1" />
<input class="id" id="idnumber8" maxlength="1" />
<input class="id" id="idnumber9" maxlength="1" />
<input class="id" id="idnumber10" maxlength="1" />
<input class="id" id="idnumber11" maxlength="1" />
<input class="id" id="idnumber12" maxlength="1" />
<input class="id" id="idnumber13" maxlength="1" /><span id="status"></span>
<p> <input type="submit" id="check" value="Check" /> </p>
</form>
<div id="result"> </div>
非常感谢您的帮助。您可以尝试以下方法:
$('#myInput').focus(function(){
$(this).next('input').focus();
})
或
两者都取自。您可以尝试以下方法:
$('#myInput').focus(function(){
$(this).next('input').focus();
})
或
这两种方法都取自。您可以使用
keyup
和next
方法:
$('input.id').on('keyup', function(){
if (this.value.match(/\d+/)) {
var $this = $(this);
if ($this.next('input').length) {
$this.next().focus();
} else {
Validate()
}
}
})
function Validate() {
jQuery('#error p').remove();
var error = jQuery('#error');
var idNumber = $('input.id').map(function(){
return this.value
}).get().join('');
}
您可以使用
keyup
和next
方法:
$('input.id').on('keyup', function(){
if (this.value.match(/\d+/)) {
var $this = $(this);
if ($this.next('input').length) {
$this.next().focus();
} else {
Validate()
}
}
})
function Validate() {
jQuery('#error p').remove();
var error = jQuery('#error');
var idNumber = $('input.id').map(function(){
return this.value
}).get().join('');
}
试试下面的方法
jQuery('.id').bind({keyup:function(){$(this).next().focus()}});
更新:尝试以下方法
jQuery('.id').bind({keyup:function(){$(this).next().focus()}});
更新:完美,是不是也在推动它请求一种方式,让它退格到字段?完美,是不是也在推动它请求一种方式,让它退格到字段?