php中post传递数组很容易,但是get传递数组就....
下面实现办法:
提交后:
- <!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(){
- var items = document.getElementsByName('checkbox');
- for(var i=0; i<items.length; i++){
- 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>