Jquery验证框架无法起到做作用
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'validate.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="./js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="./js/jquery.validate.js"></script>
</head>
<script type="text/javascript">
//Jquery代码
$(document).ready(function(){
//拿到form调用验证方法
$("#empForm").validate({
rules:{
name: "required"
},
messages:{
name: "姓名不能为空"
}
});
});
</script>
<body>
<form action="" name="#empForm" id="#empForm" method="post">
Name:<input name="name" id="name"/><br/>
Password:<input type="password" name="password" id="password"/>
<input type="submit" value="User" name="submit" id="submit"/>
</form>
</body>
</html>
路径确实没错误,
------解决方案--------------------<form action="" name="#empForm" id="#empForm" method="post">
改成
<form action="" name="#empForm"
id="empForm" method="post">
$("#"+id)才能获取到指定id的元素。
------解决方案-------------------- 楼上正解.