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'];  

?>

原文地址:https://www.cnblogs.com/zzlp/p/3704537.html