jquery用添加按钮把数据传送给PHP页面
更新:HHH   时间:2023-1-7


先建一个HTML文件,命名为add.html


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html"  charset="UTF-8" />
<title>添加按钮</title>

     /*要添加好jquery库*/
    <script type="text/javascript" src="jquery-1.7.2.js"></script>
   <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
 
</head>

<body>
<form id="add_form">
  <div>
    <input type="text" name="caizhong"  value="双色球"   id="qg_ssq"/>
    <input type="checkbox" name="qihao" value="20100727" id="qihao" />
  </div>
  <div>
    <input type="submit" name="add_submit" value="添加" id="add_submit" />
  </div>
</form>


   <script type="text/javascript">
  
 $('form#add_form').submit(function() {
      var caizhong=$('input#qg_ssq').val();
   var qihao=$('input#qihao').val();
         alert($(this).serialize());
   $.ajax(
     {
      url: 'add_data.php',
      method: 'get',
      data: $(this).serialize(),
      
      success: function()
      {
       window.open("add_data.php?caizhong="+caizhong+"&qihao="+qihao);
       
       
      }        
     });
         });
  
 </script>


</body>
</html>
 

 


再建一个php页面,命名为:add_data.php


 

<meta http-equiv="Content-Type" content="text/html"  charset="UTF-8" />

<?php
$caizhong=$_GET['caizhong'];
$qihao=$_GET['qihao'];
echo $caizhong;
echo $qihao;
?>

返回web开发教程...