我遇到了一个问题。我总共有4个文本框字段,每个框都需要一个提交按钮。但我想做的是,当按下tab键时,如果这些字段为空,则不需要跳到第二个字段,否则用红色边框给出错误。[JSFidle][1]
像这样尝试
Js Fiddle
$('input').keydown(function(e) {
var code = e.keyCode || e.which;
$(this).css('border','');
if (code == '9') {
if($(this).val()==''){
$(this).next().html('this field is required!');
$(this).css('border','1px solid red');
$( this ).focus();
return;
}
}
});