jquery焦点,并在最后一个输入被填充后自动提交

jquery focus and auto submit after last input is filled

本文关键字:填充 提交 输入 焦点 最后一个 jquery      更新时间:2023-09-26

我对jquery有两种情况,

我有两个文本框(姓名、年龄),现在我需要做的是在年龄被禁用时自动聚焦加载的姓名,一旦用户输入姓名,它就会被禁用并切换到年龄文本框(启用和聚焦)。一旦填写了年龄文本框,jquery将自动提交它,不带任何按钮

现在第一件事是,我可以禁用和启用文本框,但当我放入document.name.focus()时,它不起作用,我的意思是,焦点不起作用

$(document).ready(function(){
    $('[name="age"]').blur(function(){
        if(this.value != ''){
            document.form.submit();
        }
    });
});

所以在最后一个文本框被填充后,它会自动提交,但问题是,每当我运行它时,我总是收到这个错误"注意:未定义的索引:C:''location中的名称"。

这是我的代码:

<script>
$(document).ready(function(){
	$('[name="age"]').blur(function(){
		if(this.value != ''){
			document.form.submit();
		}
	});
}); 
$(document).ready(function() {
  $('[name="name"]').blur(function() {
    var that = $('[name="age"]')[0];
    if (this.value != '') {
		this.focus();
      this.disabled = true;
      that.disabled = false;
    }
  });
});
function focusName(){	
	var count = document.form.name.value.length + 1;
	if(count <= 8){
		document.form.name.focus();
	}else{
		document.form.age.focus();
	}
}
function focusAge(){
	var count = document.form.age.value.length + 1;
	if(count <= 10){
		document.form.age.focus()		
	}else{
		document.form.submit();
	}
}
</script>
<fieldset>
<legend>Information </legend>
<form action="receive.php" method="post" name="form">
	name : <input type="text" name="name" onKeyUp="focusName();" maxlength="8"><br>
	Age : <input typr="text" name="age" disabled onKeyUp="focusAge();" maxlength="3"><br>
	<!--input type="submit"-->
</form>
</fieldset>

请帮忙!!。谢谢

一些提示:在文本框上添加一些id

示例:

name : <input type="text" id="name" name="name" onKeyUp="focusName();" maxlength="8"><br>
    Age : <input typr="text" id="age" name="age" disabled onKeyUp="focusAge();" maxlength="3">

将名称集中在加载上(使用JQuery):

$(document).ready(function(){$("#name").focus();})

自动提交您的表格:

$("form :input").focusout(function(){
   $(this).each(function(){
    if($(this).val()=="" )
    {
      return false;
    }
  });
  $("form").submit();
});