如图,当表单的三个数据都输好之后,点击空白处之后,会自动触发点击“保存”按钮,js该怎么写?谢谢。
html的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>输完数据自动点击“保存”按钮</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
姓名:<input type="text" name="textfield" /><p>
年龄:<input type="text" name="textfield2" /><p>
性别:<input type="text" name="textfield3" /><p>
<input type="button" onclick='aaa()' value="提交" />
<script>
function aaa(){
alert('点击保存一次');
}
</script>
</p>
</form>
</body>
</html>

表单
js
自动触发
保存
数据输完
------解决方案--------------------
可以设置三个输入框的onblur执行一个判断方法,判断三个输入框是否为空
------解决方案--------------------
建议楼主将button 换成submit
document.onclick=function(){
document.getElementById("form1").submit();
}
------解决方案--------------------
我上面给你的回复难道不是代码吗?
<form id="form1" name="form1" method="post" action="">
姓名:<input type="text" name="textfield" /><p>
年龄:<input type="text" name="textfield2" /><p>
性别:<input type="text" name="textfield3" /><p>
<input type="submit" onclick='aaa()' value="提交" />
<script>
document.onclick=function(){
alert('点击空白处保存信息');
document.getElementById("form1").submit();
}
</script>
------解决方案--------------------
最好是点击按钮提交,要不要是输入不对直接提交了就修改不了了,当然要这样做也行
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>输完数据自动点击“保存”按钮</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
姓名:<input type="text" name="textfield" onblur="checkOK()" /><p>
年龄:<input type="text" name="textfield2" onblur="checkOK()" /><p>
性别:<input type="text" name="textfield3" onblur="checkOK()" /><p>
<input type="button" onclick='aaa()' value="提交" />
<script>
function checkOK() {
var f = document.form1;
if (f.textfield.value != '' && f.textfield2.value != '' && f.textfield3.value != '') aaa();
}
function aaa() {
alert('点击保存一次');
}
</script>
</p>
</form>
</body>
</html>