jquery的each方法取值ajax傳送陣列 php取得值
阿新 • • 發佈:2019-02-07
HTML檔案程式碼
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文件</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script> <script src="../layer/layer.js"></script> </head> <body> <input type="checkbox" value="1" />1 <br /> <input type="checkbox" value="2" />2 <br /> <input type="checkbox" value="3" />3 <br /> <input type="checkbox" value="4" />4 <br /> <input type="submit" id="add_submit" name="add_submit" value="修改"/> <script type="text/javascript"> var sel=""; $('input#add_submit').click(function() { $("input:checked").each(function(i) { sel += $(this).val() + "|"; }); //alert(sel); var url="03.php?action=addsale2&id=<?php echo $id?>&t3="+sel; //Ajax獲取 $.post(url, {}, function(str){ layer.open({ /*type: 1, content: str */ type: 1, skin: 'layui-layer-rim', //加上邊框 area: ['420px', '240px'], //寬高 content: str }); }); }); </script> </body> </html>
註釋:<script src="../layer/layer.js"></script>
同時引用了JS彈窗外掛,使用方法請到官網上找:http://layer.layui.com/
PHP程式碼 03.php
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8" />
<?php
$t3=$_GET['t3'];
$msg='t3='.$t3;
echo $msg;
?>