注册 登录
编程论坛 JavaScript论坛

js 表单验证问题 求指教

xiaozhumt 发布于 2011-03-07 14:47, 621 次点击
<head>
<script type="text/javascript">
  function form_validator(theform)
        {
            if (document.luntan.pwd.value=="")
              {
                document.newenterprise.pwd.focus();
                alert("密码不能为空");
                return false;
               }
            }
            return(true)
            </script>
</head>
<body>
<form name="luntan" method="post"  onsubmit="return form_validator(this);">
      <input type="text" name="pwd">
      <label>
      <input type="submit" name="Submit" value="提交" />
      </label>
</form>
</body>

验证不出去啊  求高手指教一下 谢
还有就是关于Introduction像这个是什么函数?做表单验证的需要特定的对应函数么?比如我看到好多Enterprise_Telephone/Name/Address 求指教
6 回复
#2
xiaozhumt2011-03-07 15:35
if (document.luntan.pwd.value=="")
              {
                theform.pwd.focus();
                alert("密码不能为空");
                return false;
               }


哈哈  自己给自己解答  我会啦!~
#3
撒布拉斯2011-03-07 16:58
那我想你问下你
theform.pwd.focus();focus是涮新吗
return form_validator(this);">this又是什么意思呢
请教!!

#4
aspic2011-03-07 17:25
以下是引用撒布拉斯在2011-3-7 16:58:54的发言:

那我想你问下你
theform.pwd.focus();focus是涮新吗
return form_validator(this);">this又是什么意思呢
请教!!
xx.focus();//是xx对象获取焦点
return form_validator(this);//这里的this就是form对象
#5
xiaozhumt2011-03-08 09:09
回复 4楼 aspic
请教为什么我的焦点无法返回呢?我贴了帖子  还没看呢 看到了这个帖子的回复  就先问一下哈   就是点击确定后焦点不返回  即没有光标啊??
#6
gupiao1752011-03-08 21:55
以下是引用xiaozhumt在2011-3-8 09:09:07的发言:

请教为什么我的焦点无法返回呢?我贴了帖子  还没看呢 看到了这个帖子的回复  就先问一下哈   就是点击确定后焦点不返回  即没有光标啊??

         document.newenterprise.pwd.focus();
                alert("密码不能为空");
                return false;
 原因分析:

  三个代码里只有一个会返回退出函数,就是return false;其他都是一个接着一个执行,    document.newenterprise.pwd.focus();这个获得焦点,但是却没有退出函数,接着alert了一个信息“密码不能为空”,这时候焦点变成了windows,也就看起来焦点获取无效,最后返回!
#7
xiaozhumt2011-03-09 09:39
回复 6楼 gupiao175
灰常的感谢!~
1