(五)struts2- 2.3.15.3 spring3.2.4 mybatis-3.2.3 jquery.validationEngine表单验证



下载jQuery-Validation-Engine-2.6.2.zip,并解压,

(五)struts2- 2.3.15.3 spring3.2.4 mybatis-3.2.3 jquery.validationEngine表单验证_第1张图片

拷贝jqueryjs/jquery.validationEngine.js文件到WebRoot/jquery下,拷贝js/languages/jquery.validationEngine-zh_CN.js文件到WebRoot/jquery下,拷贝cssvalidationEngine.jquery.css文件至WebRoot/jquery/css下。

test.jsp页面中引入

<linkrel="stylesheet"type="text/css"href="./jquery/css/validationEngine.jquery.css"/>

<scripttype="text/javascript"src="./jquery/jquery.validationEngine.js"></script>

<scripttype="text/javascript"src="./jquery/jquery.validationEngine-zh_CN.js"></script>

在页面加载完成后执行下面语句

        myformform标识Id

$("#myform").validationEngine({

          // 属性promptPosition : "bottomLeft"

      });

在需要验证的输入框中加入class="validate[required,minSize[1],maxSize[10]]"

具体validate属性参考jquery.validationEngineApi

test.jsp


<%@ page contentType="text/html; charset=UTF-8"%>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="./jquery/css/validationEngine.jquery.css" />
<script type="text/javascript" src="./jquery/jquery-1.9.1.js"></script>
<script type="text/javascript" src="./jquery/jquery.validationEngine.js"></script>
<script type="text/javascript" src="./jquery/jquery.validationEngine-zh_CN.js"></script>

<script type="text/javascript">
	function insertTest() {
		$("#myform").submit();
	}
	function listTest() {
		var myform = document.forms[0];
		myform.action = "Test!list.action";
		myform.method = "post";
		myform.submit();
	}
	function init(){
		$("#myform").validationEngine({
			//  属性promptPosition : "bottomLeft"
		});
	}
</script>


</head>
<body  onload="init();">
	<h1>样例</h1>
	<hr>
	<form name="myform" id="myform" action="Test!save.action" method="post">
		id: <input type="text" name="test.id"  class="validate[required]"> <br> <br> 
		name: <input type="text" name="test.name" class="validate[required,minSize[1],maxSize[10]]" > <br> 
		<input type="button" name="btninsert" onclick="insertTest()" value="增加" />
		<input type="button" name="btninsert" onclick="listTest()" value="列表页面" />
	</form>
</body>
</html>

部署到tomcat下访问http://localhost:8080/Test/test.jsp

(五)struts2- 2.3.15.3 spring3.2.4 mybatis-3.2.3 jquery.validationEngine表单验证_第2张图片


你可能感兴趣的:((五)struts2- 2.3.15.3 spring3.2.4 mybatis-3.2.3 jquery.validationEngine表单验证)