<form id="myform" name="myform" method="post" onsubmit="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>
<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>
以上是比较常用的几种表单提交方式,但绝不局限于这些
作者:itmyhome
出处:http://blog.csdn.net/itmyhome1990/article/details/41849175
时间: 2024-10-16 22:50:46