我有一个表单,我在其中使用 ajax 调用将其提交给 servlet。问题是我无法验证它,因为我正在使用按钮提交表单。我遇到了这个链接,但我无法找到解决我的问题 jQuery form validation on button click
我的html代码是:
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8/jquery.validate.min.js"></script>
<style type="text/css">
<%@include file="/formsub/formstyle.css" %>
</style>
<script>
$(document).ready(function(){
$( ".datepicker" ).datepicker({
altFormat: 'yyyy-mm-dd'
});
var form = $('#form1');
$(".submit").click(function(){
alert("in click");
$(form).validate({
submitHandler: function(form) {
$.get(form.attr('action'),$(form).serialize(),function(data,status){
$('#json').val(" Firstname is "+data.firstname
+"\n Lastname is "+data.lastname
+"\n You are a " +data.sex
+"\n Your interests are " +data.interest
+"\n Date of birth " +data.datepicker
+"\n Your ipaddress " +data.userIpAddress )
});
}
});
});
});
</script>
</head>
点击函数被调用,但验证没有发生。我正在使用按钮,因为我不希望页面刷新。任何帮助将不胜感激,在此先感谢