导入相应的js,css框架
<link type="text/css" rel="stylesheet"
href="<%=basePath %>js/validate/css/validate.css" />
<script src="<%=basePath %>js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="<%=basePath %>js/validate/talent-validate-all.js" type="text/javascript"></script>
写出相应的html代码
<script>
function checked(){
先判断validate框架 然后可以继续其他的js判断
if(validateForm('myform') == false){
return false;
}
}
</sctipt>
<form name="myform" action="sys/song/updateSongInfo.action" method="post" enctype="multipart/form-data" οnsubmit="return checked();">
<td>歌手名称:</td>
<td><input type="text" name="singerName" id="singerName" value="<s:property value="song.singerName"/>"/></td>
</tr>
<tr>
<td>歌曲名称:</td>
<td><input type="text" name="songName" id="songName" value="<s:property value="song.songName"/>"/></td>
</tr>
调用框架
<script type="text/javascript">
new RequiredValidator().add(new Field("歌曲类型","songType"),new Field("歌手名","singerName"));
new RegexValidator().set(new RegExp("[0-9]+(?:\.[0-9]+)?"),"只能数字").add("songPrice");
validateErrorMsgDisplayStyle = 'alert';
//validateErrorMsgDisplayStyle = 'text';
</script>
转载于:https://blog.51cto.com/hzywy/743222