<html>
<head>
<meta charset="UTF-8" />
<title></title>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<form id="myform" name="myform" method="post" οnsubmit="return sumbitTest();" action="RegisterAction.action">
<table>
<tr>
<td>姓名:</td>
<td> <input type="text" name="name" /> </td>
</tr>
<tr>
<td>性别:</td>
<td>
<input type="radio" name="sex" value="1"> 男
<input type="radio" name="sex" value="0"> 女
</td>
</tr>
<tr>
<td>年龄:</td>
<td>
<select name="age">
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Submit普通提交">
<input type="button" id="ajaxBtn" value="AJAX提交" />
<input type="button" id="jqueryBtn" value="jQuery提交" />
<input type="button" id="jsBtn" value="JS提交" />
<input type="submit" value="onSubmit提交" />
</td>
</tr>
</table>
</form>
</body>
<script type="text/javascript">
$(function() {
//ajax提交
$("#ajaxBtn").click(function() {
var params = $("#myform").serialize();
$.ajax({
type: "POST",
url: "RegisterAction.action",
data: params,
success: function(msg) {
alert("success: " + msg);
}
});
})
//jQuery提交
$("#jqueryBtn").click(function() {
$("#myform").submit();
})
//js提交
$("#jsBtn").click(function() {
document.myform.action = "RegisterAction.action";
document.myform.submit();
})
})
function sumbitTest() {
return true; //return false则不会提交
}
</script>
</html>
<head>
<meta charset="UTF-8" />
<title></title>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<form id="myform" name="myform" method="post" οnsubmit="return sumbitTest();" action="RegisterAction.action">
<table>
<tr>
<td>姓名:</td>
<td> <input type="text" name="name" /> </td>
</tr>
<tr>
<td>性别:</td>
<td>
<input type="radio" name="sex" value="1"> 男
<input type="radio" name="sex" value="0"> 女
</td>
</tr>
<tr>
<td>年龄:</td>
<td>
<select name="age">
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Submit普通提交">
<input type="button" id="ajaxBtn" value="AJAX提交" />
<input type="button" id="jqueryBtn" value="jQuery提交" />
<input type="button" id="jsBtn" value="JS提交" />
<input type="submit" value="onSubmit提交" />
</td>
</tr>
</table>
</form>
</body>
<script type="text/javascript">
$(function() {
//ajax提交
$("#ajaxBtn").click(function() {
var params = $("#myform").serialize();
$.ajax({
type: "POST",
url: "RegisterAction.action",
data: params,
success: function(msg) {
alert("success: " + msg);
}
});
})
//jQuery提交
$("#jqueryBtn").click(function() {
$("#myform").submit();
})
//js提交
$("#jsBtn").click(function() {
document.myform.action = "RegisterAction.action";
document.myform.submit();
})
})
function sumbitTest() {
return true; //return false则不会提交
}
</script>
</html>