完整代码如下:
<form action="?act=s" name=f method="post"> <select size="5" name="posTypeSelect[]" multiple="multiple" id="posTypeSelect" style="width:240px"> <option value=1>项目1</option> <option value=2>项目2</option> <option value=3>项目3</option> </select> <input type="submit" id="su" value="开始搜索" onClick="return CheckInput()" > </form> <script language="javascript"> <!-- function SelectAll(Objname) { ObjID = document.getElementById(Objname); if (ObjID != -1) { for (i=0; i<ObjID.length; i++) ObjID.options[i].selected = true; } } function CheckInput() { SelectAll("posTypeSelect"); } // --> </SCRIPT>
说明:
onClick="return CheckInput()" //所有全选所有项目。
关键内容:
name="posTypeSelect[]"
id="posTypeSelect"
获取值的循环过程:
$ap=""; $temp_x=$_POST[posTypeSelect]; for($i=0;$i<count($temp_x);$i++){ $ap=$ap.$temp_x[$i].","; } $z=substr($ap,0,-1);//去除末尾单引号职位分类