【发布时间】:2011-08-25 11:03:48
【问题描述】:
我正在使用以下脚本在每个文本框上绑定一个按键事件,以便在达到最大长度时,焦点将切换到下一个输入字段。将类名作为参数传递给函数。
function autoFocusPhoneFields(txtbox1ID,txtbox2ID) {
$('input.'+txtbox1ID+', input.'+txtbox2ID+'').each(function() {
$(this).bind('keypress', function(){
if(this.value.length == $(this).attr('maxlength')) {
$(this).next('input').focus();
}
});
});
}
$(document).ready(function(){
autoFocusPhoneFields('mobileprefix','mobilecode');
});
正如我提到的两个不同的输入......它运行良好。但是有什么办法可以让它获取类名并遍历每个输入框以附加按键事件。
【问题讨论】:
标签: javascript jquery