深入探讨PHP下拉框选择的实现方法_PHP教程

WBOY
풀어 주다: 2016-07-15 13:34:37
원래의
1092명이 탐색했습니다.

实现

第一种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. }  
  11. // print_r($_POST);  
  12. $xing="xing";  
  13. $fang="fang";  
  14. echo ' a href=del_03.php?id='.$xing.'
    &action='.$fang.'>flx /a>';  
  15. //php中,在删除内容时,给的提示的写法; href 后面必须加引号;  
  16. echo "n"." input type='button' 
    value='删除' onclick="if(confirm('确定要删除吗'))
    location.href='?delete=$result_manage[p_id]'}">
  17.  br> br>";  
  18. }  
  19. echo " input type='button' value='connect_next'
     onclick="location.href='del_03.php?id=
    $xing&action=$fang'
    ">";  
  20. ?> 

第二种PHP下拉框选择实现方法:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span> </span><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"button"</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">"delete"</span><span> </span><span class="attribute">onclick</span><span>=</span><span class="attribute-value">"<br>if(confirm('确定要删除吗')) location.href=<br>'del_03.php?id=xing'"</span><span class="tag">></span><span class="tag"><span> </span><span class="tag-name">br</span><span class="tag">/></span><span> </span></span></span></span></li>
<li><span class="tag"><span> </span><span class="tag-name">script</span><span> </span><span class="attribute">language</span><span>=</span><span class="attribute-value">"JavaScript"</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/javascript"</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span>function select(obj){  </span></li>
<li>
<span class="attribute">window.location.href</span><span>=</span><span class="attribute-value">'del_04.php?myselect=<br>'</span><span>+obj.options[obj.selectedIndex].value;  </span>
</li>
<li class="alt"><span>return; //可以不写;  </span></li>
<li><span>}  </span></li>
<li class="alt"><span class="tag"><span> /script</span><span class="tag">></span><span> </span></span></li>
<li><span class="tag"><span> </span><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"button"</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">"delete"</span><span> <br></span><span class="attribute">onclick</span><span>=</span><span class="attribute-value">"if(confirm('确定要删除吗')) <br>location.href='del_03.php?id=xing'"</span><span class="tag">></span><span class="tag"><span> </span><span class="tag-name">br</span><span class="tag">/></span><span> </span></span></span></li>
<li class="alt"><span class="tag"><span> </span><span class="tag-name">form</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"myform"</span><span> </span><span class="attribute">action</span><span>=</span><span class="attribute-value">"del_04.php"</span><span> <br></span><span class="attribute">method</span><span>=</span><span class="attribute-value">"post"</span><span class="tag">></span><span> </span></span></li>
<li><span class="tag"><span> !-- 直接触发onchange 事件 ,此时不用提交表单,-- </span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span class="tag"><span> !--</span><span class="tag"><span> </span><span class="tag-name">select</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"selectID"</span><span> </span><span class="attribute">onchange</span><span>=<br></span><span class="attribute-value">"location='del_04.php?myselect='+this.options<br>[this.selectedIndex].value"</span><span class="tag">></span><span>--</span><span class="tag">></span><span> </span></span></span></li>
<li><span class="tag"><span> !-- 把onchange 的事件写在一个函数里面-- </span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span class="tag"><span> </span><span class="tag-name">select</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"selectID"</span><span> </span><span class="attribute">onchange</span><span>=</span><span class="attribute-value">"select(this)"</span><span class="tag">></span><span> </span></span></li>
<li><span class="tag"><span> !-- </span><span class="tag"><span> </span><span class="tag-name">select</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"selectID"</span><span> </span><span class="tag">></span><span>--</span><span class="tag">></span><span> </span></span></span></li>
<li class="alt"><span class="tag"><span> </span><span class="tag-name">option</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">"0"</span><span class="tag">></span><span>请选择</span><span class="tag"><span> /option</span><span class="tag">></span><span> </span></span></span></li>
<li><span class="tag"><span> </span><span class="tag-name">option</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">"value1"</span><span class="tag">></span><span>option1</span><span class="tag"><span> /option</span><span class="tag">></span><span> </span></span></span></li>
<li class="alt"><span class="tag"><span> </span><span class="tag-name">option</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">"value2"</span><span class="tag">></span><span>option2</span><span class="tag"><span> /option</span><span class="tag">></span><span> </span></span></span></li>
<li><span class="tag"><span> </span><span class="tag-name">option</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">"value3"</span><span class="tag">></span><span>option3</span><span class="tag"><span> /option</span><span class="tag">></span><span> </span></span></span></li>
<li class="alt"><span class="tag"><span> /select</span><span class="tag">></span><span> </span></span></li>
<li><span class="tag"><span> </span><span class="tag-name">input</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"submit"</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"sendSelect"</span><span> <br></span><span class="attribute">value</span><span>=</span><span class="attribute-value">"提交下拉框"</span><span class="tag">/></span><span> </span></span></li>
<li class="alt"><span class="tag"><span> /form</span><span class="tag">></span><span> </span></span></li>
</ol>
로그인 후 복사

以上就是PHP下拉框的两种实现方法介绍。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445968.htmlTechArticle实现 第一种PHP下拉框实现方法: ?php //提交下拉框; //直接饱触发onchange事件的结果 $ id =$_GET['myselect'];//myselect 为location.herf?id的名字; echo$i...
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿