PHP下拉框選擇的實現方法


實現

第一種PHP下拉框實現方法:

  1. < ?php 
  2. //提交下拉框; 
  3. //直接飽觸發onchange事件的結果 
  4. $id=$_GET['myselect']; // myselect 為location.herf?id的名字; 
  5. echo $id; 
  6. //用表單提交的結果; 
  7. if($_POST["sendSelect"]){ //sendSelect 為表單的名字; 
  8. $select_val=$_POST["selectID"]; 
  9. echo "你選擇的值為: $select_val"; 
  10. // print_r($_POST); 
  11. $xing="xing"
  12. $fang="fang"
  13. echo '<ahref=del_03.php?id='.$xing.' &action='.$fang.'>flx< /a>'; 
  14. //php中,在刪除內容時,給的提示的寫法; href 后面必須加引號; 
  15. echo "n"."<inputtype='button'value='刪除'onclick="if(confirm('確定要刪除嗎'))     { location.href='?delete=$result_manage[p_id]'}">
  16. <br><br>"; 
  17. echo "<inputtype='button'value='connect_next' onclick="location.href='del_03.php?id=     $xing&action=$fang'">"; 
  18. ?>

第二種PHP下拉框選擇實現方法:

  1. <inputtype="button"value="delete"onclick=" if(confirm('確定要刪除嗎')) location.href= 'del_03.php?id=xing'"><br/>
  2. <scriptlanguage="JavaScript"type="text/javascript">
  3. function select(obj){
  4. window.location.href='del_04.php?myselect= '+obj.options[obj.selectedIndex].value;
  5. return; //可以不寫;
  6. }
  7. < /script>
  8. <inputtype="button"value="delete"onclick="if(confirm('確定要刪除嗎')) location.href='del_03.php?id=xing'"><br/>
  9. <formname="myform"action="del_04.php"method="post">
  10. < !-- 直接觸發onchange 事件 ,此時不用提交表單,-- >
  11. < !--<selectname="selectID"onchange= "location='del_04.php?myselect='+this.options [this.selectedIndex].value">-->
  12. < !-- 把onchange 的事件寫在一個函數里面-- >
  13. <selectname="selectID"onchange="select(this)">
  14. < !-- <selectname="selectID">-->
  15. <optionvalue="0">請選擇< /option>
  16. <optionvalue="value1">option1< /option>
  17. <optionvalue="value2">option2< /option>
  18. <optionvalue="value3">option3< /option>
  19. < /select>
  20. <inputtype="submit"name="sendSelect"value="提交下拉框"/>
  21. < /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'];  

?>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM