JQuery 绑定select标签的onchange事件,弹出选择的值,并实现跳转、传参(selected的值和页面其它元素的值)以及js的select

  • Post author:
  • Post category:其他


JQurey

1 <script src="jquery.min.js" type="text/javascript"></script>
 2 <script language="javascript" type="text/javascript">
 3 $(document).ready(function(){
 4 $('#mySelect').change(function(){
 5   alert($(this).children('option:selected').val());
 6   var p1=$(this).children('option:selected').val();//这就是selected的值
 7   var p2=$('#param2').val();//获取本页面其他标签的值
 8   window.location.href="xx.php?param1="+p1+"¶m2="+p2+"";//页面跳转并传参
 9   })
10 })
11 </script>
12 
13 <select id="mySelect">
14 <option value="1">one</option>
15 <option value="2" selected="selected">two</option>
16 <option value="3">three</option>
17 </select>
18 <input type="text" value="ooo" name="param2" id="param2"/>

JS

<HTML > 
<head > 
  <SCRIPT language="javascript" > 
function showpublishtel(num) 
{ 

if(num=="18") 
{ 
document.all.aa.innerText="DEF:" 
} 
if(num=="16") 
{ 
document.all.aa.innerText="ABC:" 
} 
} 
</SCRIPT > 
  </HEAD > 

  <BODY > 
<form name="form" action="" method="post" > 
<table > 
<div id="aa" >年龄: </div > 
<td > 
<SELECT id="age" name="age" οnchange="showpublishtel(this.options[this.selectedIndex].value);" >   
<OPTION value=16 >16岁  </OPTION > 
<OPTION value=18 >18岁 </OPTION >   
         <OPTION value=20 >20岁 </OPTION >  
</select > 
          </td > 
</table > 
</form > 
  </BODY > 
</HTML >