<script type="text/javascript">
$(function() {
$('#form1').submit(function() { //当提交表单时,会发生 submit 事件。
//此处可做表单验证
if ($("#username").val() == "") {
alert("用户名不能为空");
return false;
}
var postData = $("#form1").serialize(); //序列化表单,后台可正常通过post方法获取数据
$.ajax({
type: "POST",
url: "/member/member/post_member",
data: postData,
beforeSend: function() {
$("#btn-submit").attr("disabled", true);//提交表单前的处理,防止用户多次点击【登陆】,重复提交表单
$("#btn-submit").val("正在登陆...");
},
success: function(msg) {
if (msg == 0) {
alert('操作成功');
window.location.href = '/member/member';
} else {
$("#btn-submit").attr("disabled", false);
$("#btn-submit").val("登陆");
alert("用户或密码错误!");
}
}
});
});
});
</script>
<div>
<form id="form1" onsubmit="return false;"> //注意:此处必须阻止表单提交
<!--表单内容部分-->
<input type="reset" value="重置" />
<input type="submit" id="btn-submit" value="登陆" />
</form>
</div>
<html>
<head>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("form").submit(function(e) {
//e.preventDefault(); //阻止表单提交
alert("Submit prevented");
});
});
</script>
</head>
<body>
<form name="input" action="./b.php" method="get">
First name:
<input type="text" name="FirstName" value="Mickey" size="20"><br />
Last name:
<input type="text" name="LastName" value="Mouse" size="20"><br />
<input type="submit" value="Submit">
</form>
</body>
</html>