麻烦大神给看下为什么validate没验证表单就直接提交了

吹面不寒の杨柳风 2015-04-11 05:09:40

<!DOCTYPE html>
<html>
<head>
<meta charset="GBK">
<title>登录</title>
<script type="text/javascript" src="/office/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="/office/js/jquery.validate.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#login").validate({
//自定义验证规则
rules:{
userName:{required:true},
password:{required:true}
},
//自定义提示信息
/* messages:{
userName:{required:"请输入你的用户名"},
password:{required:"请输入密码"}
}, */
//定义错误信息提示位置
errorPlacement:function(error,element){
error.appendTo(".tip");
// error.appendTo(element.parent());

}
});
});
</script>
</head>
<body>
<div style="width:400px;height:250px;margin:15% auto;background:#e8f4ff;">
<div style="winth:100%;height:15%;"></div>
<form id="login" name="login" method="post" action="login.php">
<table style="width:100%;height:200px">
<tr >
<td align="right">用户名:</td>
<td><input name="userName" type="text" id="userName" onmouseover="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" size="15" /></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input name="password" type="password" id="password" onmouseover="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" size="15" /></td>
</tr>
<tr>
<td></td>
<td><span class="tip"></span></td>
</tr><tr>
<td></td>
<td><input type="submit" value="登录" name="submit" />    <input type="reset" value="重置" name="reset" /></td>
</tr>
</table>
</form>
</div>
</body>

RT
:刚开始学jq,没明白到底哪里错了,请大神们帮看下,谢谢
...全文
439 3 打赏 收藏 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 1 楼 gj716 的回复:
你引入的js路径不对吧,如你的html是放在1文件夹里,jquery-1.9.1.js和jquery.validate.js两个js有没有放到1/office/js文件夹下,我copy你的代码试是没有问题的,如下图所示
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>登录</title>
        <script type="text/javascript" src="jquery-1.4.2.js"></script>
        <script type="text/javascript" src="jquery.validate.js"></script>
        <script type="text/javascript">
                    $(document).ready(function(){
                    $("#login").validate({
                            //自定义验证规则
                                      rules:{
                                         userName:{required:true},
                                         password:{required:true}
                                          },
                                      //自定义提示信息
                                     /* messages:{
                                         userName:{required:"请输入你的用户名"},
                                          password:{required:"请输入密码"}
                                         }, */
                                      //定义错误信息提示位置
                                     errorPlacement:function(error,element){
                                         error.appendTo(".tip");
                                        // error.appendTo(element.parent());

                                     }
                            });
                    });
        </script>
    </head>
    <body>
      <div style="width:400px;height:250px;margin:15% auto;background:#e8f4ff;">
          <div style="winth:100%;height:15%;"></div>
                <form id="login" name="login" method="post" action="1.html">
                  <table style="width:100%;height:200px">
                    <tr >
                      <td align="right">用户名:</td>
                      <td><input name="userName" type="text" id="userName" onmouseover="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" size="15" /></td>
                    </tr>
                    <tr>
                      <td align="right">密码:</td>
                      <td><input name="password" type="password" id="password"  onmouseover="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" size="15" /></td>
                    </tr>
                    <tr>
                      <td></td>
                      <td><span class="tip"></span></td>
                    </tr>
                    <tr>
                      <td></td>
                      <td><input type="submit" value="登录"  name="submit" />    <input type="reset" value="重置" name="reset" /></td>
                    </tr>
                  </table>
                  </form>
        </div>
      </body>
</html>
自己找到问题所在了,感谢热心回复
  • 打赏
  • 举报
回复
你发布网站没有,没有方步不要使用/office/这种绝对路径,会导致你js文件路径可能不对
V非凡 2015-04-11
  • 打赏
  • 举报
回复
你引入的js路径不对吧,如你的html是放在1文件夹里,jquery-1.9.1.js和jquery.validate.js两个js有没有放到1/office/js文件夹下,我copy你的代码试是没有问题的,如下图所示







<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录</title>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" src="jquery.validate.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#login").validate({
//自定义验证规则
rules:{
userName:{required:true},
password:{required:true}
},
//自定义提示信息
/* messages:{
userName:{required:"请输入你的用户名"},
password:{required:"请输入密码"}
}, */
//定义错误信息提示位置
errorPlacement:function(error,element){
error.appendTo(".tip");
// error.appendTo(element.parent());

}
});
});
</script>
</head>
<body>
<div style="width:400px;height:250px;margin:15% auto;background:#e8f4ff;">
<div style="winth:100%;height:15%;"></div>
<form id="login" name="login" method="post" action="1.html">
<table style="width:100%;height:200px">
<tr >
<td align="right">用户名:</td>
<td><input name="userName" type="text" id="userName" onmouseover="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" size="15" /></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input name="password" type="password" id="password" onmouseover="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" size="15" /></td>
</tr>
<tr>
<td></td>
<td><span class="tip"></span></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="登录" name="submit" />    <input type="reset" value="重置" name="reset" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>

87,984

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧