php中post傳遞數組很容易,但是get傳遞數組就....
下面實作辦法:
<a href="http://blog.51cto.com/attachment/201302/142102796.jpg" target="_blank"></a>
送出後:
<a href="http://blog.51cto.com/attachment/201302/142121233.jpg" target="_blank"></a>
<!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=gbk" />
<title>php中$_GET傳遞數組的實作</title>
</head>
<body><script type="text/javascript">
function selectItems(){
var items = document.getElementsByName('checkbox');
var values = new Array();
var key = 0;
for(var i=0; i<items.length; i++){
if(items[i].checked){
values[key] = items[i].value
key++;
}
}
if(values.length > 0){
alert(values.join(','));
window.location.href='admin_news_list.php?cid='+values.join(',');
}else{
alert('未選擇項目!');
}
function selectAll(){
items[i].checked = true;
</script>
<form id="form1" name="form1" method="post" action="">
<input type="checkbox" name="checkbox" id="checkbox1" value="1"/>1<br />
<input type="checkbox" name="checkbox" id="checkbox2" value="2"/>2<br />
<input type="checkbox" name="checkbox" id="checkbox3" value="3"/>3<br />
<input type="checkbox" name="checkbox" id="checkbox4" value="4"/>4<br />
<input type="checkbox" name="checkbox" id="checkbox5" value="5" />5<br />
<input type="checkbox" name="checkbox" id="checkbox6" value="6"/>6<br />
<input type="checkbox" name="checkbox" id="checkbox7" value="7"/>7<br />
<input type="checkbox" name="checkbox" id="checkbox8" value="8"/>8<br />
<input type="checkbox" name="checkbox" id="checkbox9" value="9"/>9<br />
<input type="checkbox" name="checkbox" id="checkbox10" value="10"/>10<br />
<input type="checkbox" name="checkbox" id="checkbox11" value="11"/>11<br />
<input type="checkbox" name="checkbox" id="checkbox12" value="12"/>12<br />
<input type="checkbox" name="checkbox" id="checkbox13" value="13"/>13<br />
<input type="checkbox" name="checkbox" id="checkbox14" value="14"/>14<br />
<input type="checkbox" name="checkbox" id="checkbox15" value="15"/>15<br />
<input type="checkbox" name="checkbox" id="checkbox16" value="16"/>16<br />
<input type="checkbox" name="checkbox" id="checkbox17" value="17"/>17<br />
<input type="checkbox" name="checkbox" id="checkbox18" value="18"/>18<br />
<input type="checkbox" name="checkbox" id="checkbox19" value="19"/>19<br />
<input name="btn" type="button" id="btn" value="選擇" onclick="selectItems();"/>
<input name="btn" type="button" id="btn" value="全部" onclick="selectAll();"/>
</form>
</body>
</html>
本文轉自許琴 51CTO部落格,原文連結:http://blog.51cto.com/xuqin/1135505,如需轉載請自行聯系原作者