使用jQuery Form Plugin获取表单信息
很多时候我们需要跟表单打交道,今天介绍一种jQuery Form Plugin获取表单信息的方法,需要引用官方的js,更多官方例程,点此直达
1 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 2 <script src="http://malsup.github.com/jquery.form.js"></script>
其他跟普通的ajax方法类似,直接放出我测试程序的全部源代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <html> 2 <head> 3 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 4 <script src="http://malsup.github.com/jquery.form.js"></script> 5 <script> 6 7 // wait for the DOM to be loaded 8 9 $(document).ready(function() { 10 11 // prepare Options Object 12 13 var options = { 14 url: 'comment.php', 15 //覆盖表单中的action url 16 17 success: function() { 18 alert('Thanks for your comment!'); 19 //成功返回信息 20 21 } 22 }; 23 24 // pass options to ajaxForm 25 26 $('#myForm').ajaxForm(options); 27 }); 28 </script> 29 </head> 30 <body> 31 <form id="myForm" action="comment1.php" method="post"> 32 Name: <input type="text" name="name" /> 33 Comment: <textarea name="comment"></textarea> 34 <input type="submit" value="Submit Comment" /> 35 </form> 36 </body> 37 </html>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 /* 2 *我将获取到的结果写进文本以此确认已经接收到表单信息 3 */ 4 5 <?php 6 $name=$_POST['name']; 7 $fp=fopen("1.txt","w+"); 8 fputs($fp,$name); 9 fclose($fp); 10 ?>