實現
第一種PHP下拉框實現方法:
- < ?php
- //提交下拉框;
- //直接飽觸發onchange事件的結果
- $id=$_GET['myselect']; // myselect 為location.herf?id的名字;
- echo $id;
- //用表單提交的結果;
- if($_POST["sendSelect"]){ //sendSelect 為表單的名字;
- $select_val=$_POST["selectID"];
- echo "你選擇的值為: $select_val";
- }
- // print_r($_POST);
- $xing="xing";
- $fang="fang";
- echo '<ahref=del_03.php?id='.$xing.' &action='.$fang.'>flx< /a>';
- //php中,在刪除內容時,給的提示的寫法; href 后面必須加引號;
- echo "n"."<inputtype='button'value='刪除'onclick="if(confirm('確定要刪除嗎')) { location.href='?delete=$result_manage[p_id]'}">
- <br><br>";
- }
- echo "<inputtype='button'value='connect_next' onclick="location.href='del_03.php?id= $xing&action=$fang'">";
- ?>
第二種PHP下拉框選擇實現方法:
- <inputtype="button"value="delete"onclick=" if(confirm('確定要刪除嗎')) location.href= 'del_03.php?id=xing'"><br/>
- <scriptlanguage="JavaScript"type="text/javascript">
- function select(obj){
- window.location.href='del_04.php?myselect= '+obj.options[obj.selectedIndex].value;
- return; //可以不寫;
- }
- < /script>
- <inputtype="button"value="delete"onclick="if(confirm('確定要刪除嗎')) location.href='del_03.php?id=xing'"><br/>
- <formname="myform"action="del_04.php"method="post">
- < !-- 直接觸發onchange 事件 ,此時不用提交表單,-- >
- < !--<selectname="selectID"onchange= "location='del_04.php?myselect='+this.options [this.selectedIndex].value">-->
- < !-- 把onchange 的事件寫在一個函數里面-- >
- <selectname="selectID"onchange="select(this)">
- < !-- <selectname="selectID">-->
- <optionvalue="0">請選擇< /option>
- <optionvalue="value1">option1< /option>
- <optionvalue="value2">option2< /option>
- <optionvalue="value3">option3< /option>
- < /select>
- <inputtype="submit"name="sendSelect"value="提交下拉框"/>
- < /form>
以上就是PHP下拉框的兩種實現方法介紹。
前兩種方法選擇后會刷新頁面,刷新頁面后列表框恢復默認值
以下方法再刷新后 保留選擇的值
<select id="aa" name="aa" onChange="location='aa.php?aaselect='+this.options[this.selectedIndex].value" >
<option value="1" <? if($aaid=="1"){ echo "selected";}?>>全部類別</option>
<option value="2"<? if($aaid=="2"){ echo "selected";}?>>服裝</option>
<option value="3"<? if($aaid=="3"){ echo "selected";}?>>鞋</option>
<option value="4"<? if($aaid=="4"){ echo "selected";}?>>理發</option>
<option value="5"<? if($aaid=="5"){ echo "selected";}?>>美食</option>
</select>
<?php if($_GET['aaselect']) $aaid=$_GET['aaselect'];
?>