我有一个表单,我希望ENTER的动作移动到下一个输入字段而不是提交表单。我已经尝试了下面的代码和一百个变体,但我明显做错了什么。 将ENTER函数更改为TAB
24行总是计算0的长度,所以27从不执行。 这是因为文字而不是图像:
$('form input').keydown(function(e) {
// The this keyword is <div id="input_form">
if(e.keyCode == 13){
e.preventDefault(); // cancel default 13 key behaviour (submitting form)
var n = $(this).next('input').length;
console.log("nexts=" + n);
if($(this).next('input').length) { // if there's another field
$(this).next('input').focus(); // move focus to next field in form
}
else {
$(this).blur();
}
}
});
形式是
<form action="" class="my_input_form" enctype="multipart/form-data" id="my_input_form_5" method="post" name="">
<!-- First Name -->
<div id="first_name_wrap" class="field_wrap" >
<label for="first_name" id="first_name_label" class="form_label">First Name</label>
<br />
<input id="first_name" class="field_input" name="first_name" placeholder="" type="text" value="<?php echo $first_name?>">
<div class="form_field_error" id="first_name_error" style="display:none;"></div>
</div>
<!-- Last Name -->
<div id="last_name_wrap" class="field_wrap">
<label for="last_name" id="last_name_label" class="form_label">Last Name</label>
<br />
<input id="last_name" class="field_input" name="last_name" placeholder="" type="text" value="<?php echo $last_name?>">
<div class="form_field_error" id="last_name_error" style="display:none;"></div>
</div>
有谁看到这个问题?
为什么第一个代码是图像?你能把它作为文本提供吗? –
是的,请参阅上文。 – Steve