对于PHP的学习,除了书本上的了解之外,最重要的要数实际的编程实践。我们要聪实践中不断的积累经验。比如本文介绍的两种PHP下拉框选择实现方法就是经验之谈。
实现PHP下拉框的选择可以有很多方法,我们在这里就为大家介绍两种常用简单的实现PHP下拉框选择的方法,希望对有需要的朋友有所帮助。#t#
***种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">
- functionselect(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下拉框的两种实现方法介绍。
转载请说明出处
知优网 » 深入探讨PHP下拉框选择的实现方法(php下拉列表框)
知优网 » 深入探讨PHP下拉框选择的实现方法(php下拉列表框)