永发信息网

js判断循环多个表单问题

答案:3  悬赏:40  手机版
解决时间 2021-01-24 01:50
  • 提问者网友:疯子也有疯子的情调
  • 2021-01-23 18:26
一下三个表单是循环出来的,我想用js判断点击各自的提交按钮,不如我点击按钮一的时候判断表单一不能为空,如果不为空那么获取一的焦点,点击提交二的时候判断二表单不能为空,获取二的焦点......, 各管各的怎么判断?
往高手指点?
<form name="form" action='form.php' method="post" onsubmit="return show()">
<input type="text" name="name" id="name1" />
<input type="submit" name="submit" value="提交">
</form>
<form name="form" action='form.php' method="post" onsubmit="return show()">
<input type="text" name="name" id="name2" />
<input type="submit" name="submit" value="提交">
</form>
<form name="form" action='form.php' method="post" onsubmit="return show()">
<input type="text" name="name" id="name3" />
<input type="submit" name="submit" value="提交">
</form>
................
..................
最佳答案
  • 五星知识达人网友:woshuo
  • 2021-01-23 18:55
<form name="form" action='form.php' method="post" onsubmit="return show()">改成
<form name="form1" action='form.php' method="post" onsubmit="return show(form1)">
<form name="form2" action='form.php' method="post" onsubmit="return show(form2)">
<form name="form3" action='form.php' method="post" onsubmit="return show(form3)">

js 函数里
function show(obj){
var f=document.obj;
if(obj=='form1'){}
if(obj=='form2'){}
if(obj=='form3'){}
}
全部回答
  • 1楼网友:刀戟声无边
  • 2021-01-23 19:34
把onsubmit="return show()" 改为onsubmit="return show(this.firstChild.value)" 然后在show函数里判断传入变量的值是否为空
  • 2楼网友:妄饮晩冬酒
  • 2021-01-23 19:12
a
b
c
d
<script> function check() { var formnodes = document.getelementsbytagname('form'); for(var i=1;i<=formnodes.length;i++) { // 这里是遍历所有表单的做判断 var finished_num = document.forms['form'+i].finished_num.value; var cont = document.forms['form'+i].cont.value; alert(finished_num) alert(cont) } } </script> 这是一个静态的 具体的你用php把他拼出来 html的表单名,什么的 现在我有点没明白你的需求可能,这上也说不清楚,要不有空的时候百度hi吧
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯