这可能是愚蠢的事 - 我不是编码器所以我只是尝试一个简单的复制和粘贴我需要的功能。
这是我想要的: http://jsfiddle.net/skram/qygB2/4/
$(function() {
var charLimit = 1;
$(".inputs").keydown(function(e) {
var keys = [8, 9, /*16, 17, 18,*/ 19, 20, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 144, 145];
if (e.which == 8 && this.value.length == 0) {
$(this).prev('.inputs').focus();
} else if ($.inArray(e.which, keys) >= 0) {
return true;
} else if (this.value.length >= charLimit) {
$(this).next('.inputs').focus();
return false;
} else if (e.shiftKey || e.which <= 48 || e.which >= 58) {
return false;
}
}).keyup (function () {
if (this.value.length >= charLimit) {
$(this).next('.inputs').focus();
return false;
}
});
});
它在那里效果很好。
现在 - 如果我将它逐字复制并粘贴到我的wordpress页面中,它就会失败。
这里是在测试网站上直播
http://bangforbuck.co.uk/111-2/
所以我把它复制到wordpress页面上:
<input class="inputs" type="text" class="inputs" />
<input class="inputs" type="text" class="inputs" />
<input class="inputs" type="text" class="inputs" />
<input class="inputs" type="text" class="inputs" />
<input class="inputs" type="text" class="inputs" />
<input class="inputs" type="text" class="inputs" />
和上面的js成了一个“插入脚本头”插件。
现在autotab无法工作......所以我想我有一些基本的,基础的,错的?
谢谢你的时间。缺口
答案 0 :(得分:0)
Auto-Tabing JS代码已经适用于“Check Numbers”按钮下方的输入字段。但只有差异是“检查数字”按钮上方的所有输入字段的“id”不同。
因此,如果您想保留“检查号码”按钮上方和下方的两个输入字段,请在页面中包含下面提到的代码段,否则如果您只想保留“检查号码”上方的输入字段数字“按钮然后使用JS代码而不是JS代码:
$(function() {
var charLimit = 1;
$(".inputs").keydown(function(e) {
var keys = [8, 9, /*16, 17, 18,*/ 19, 20, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 144, 145];
if (e.which == 8 && this.value.length == 0) {
if (this.id=="n2"){
$('#n1').focus();
}else
if (this.id=="n3"){
$('#n2').focus();
}else
if (this.id=="n4"){
$('#n3').focus();
}else
if (this.id=="n5"){
$('#n4').focus();
}else
if (this.id=="n6"){
$('#n5').focus();
};
} else if ($.inArray(e.which, keys) >= 0) {
return true;
} else if (this.value.length >= charLimit) {
if (this.id=="n1"){
$('#n2').focus();
}else
if (this.id=="n2"){
$('#n3').focus();
}else
if (this.id=="n3"){
$('#n4').focus();
}else
if (this.id=="n4"){
$('#n5').focus();
}else
if (this.id=="n5"){
$('#n6').focus();
}else
if (this.id=="n6"){
$('#n7').focus();
};
return false;
} else if (e.shiftKey || e.which <= 48 || e.which >= 58) {
return false;
}
}).keyup (function () {
if (this.value.length >= charLimit) {
if (this.id=="n1"){
$('#n2').focus();
}else
if (this.id=="n2"){
$('#n3').focus();
}else
if (this.id=="n3"){
$('#n4').focus();
}else
if (this.id=="n4"){
$('#n5').focus();
}else
if (this.id=="n5"){
$('#n6').focus();
}else
if (this.id=="n6"){
$('#n7').focus();
};
return false;
}
});
});