1. 程式人生 > >下拉框選中一個選項後 觸發事件

下拉框選中一個選項後 觸發事件

第一個例項

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
  <script language="JavaScript">
  <!--
    function GaiBian(osel){
if(osel.options[osel.selectedIndex].text==1){alert(11);}
    }
  //-->
  </script>
 </head>
 
 <body>
  <select name='selectSS' onChange="GaiBian(this)">
  <option value='1'>1 </option> 
  <option value='2'>2 </option> 
  <option value='3'>3 </option> 
  </select> 
  <select  onchange="window.location.href=this.options[this.selectedIndex].value">
    <option value="http:\\www.baidu.com">百度</option>
    <option value="http:\\www.google.cn">谷歌</option>
</select> 
 </body>
</html>


第二個例項

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
  <script language="JavaScript">
  <!--
    function GaiBian(osel){
			 var target=document.getElementById('contentid');
		if(osel.options[osel.selectedIndex].value==1){

<pre name="code" class="html">		//if(osel.options[osel.selectedIndex].text==1){
target.style.display="block"; } if (osel.options[osel.selectedIndex].value==2){target.style.display="none"; } } //--> </script> </head> <body> <select name='selectSS' onChange="GaiBian(this)"> <option value='1'>1 </option> <option value='2'>2 </option> </select> <div id="contentid" class="none">開啟的內容</div> </body></html>
		if(osel.options[osel.selectedIndex].value==1){