首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

JQ控制DropDownList选中解决方法

2012-06-08 
JQ控制DropDownList选中asp:DropDownList IDdocumentname_2 runatserver asp:ListItem护照/asp

JQ控制DropDownList选中
<asp:DropDownList ID="documentname_2" runat="server" >
  <asp:ListItem>护照</asp:ListItem>
  <asp:ListItem>港澳通行证</asp:ListItem>
  <asp:ListItem>台湾通行证</asp:ListItem>
  <asp:ListItem>台胞证</asp:ListItem>
  <asp:ListItem>回乡证</asp:ListItem>
  <asp:ListItem>国际海员证</asp:ListItem>
  </asp:DropDownList>
<a>初始</a>

当我点击初始的时候 自动选中护照 用JQ怎么实现

[解决办法]
先给你个javascript版本:

JScript code
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title></title><script type="text/javascript"> function Test(){   var obj=document.getElementById("test");   for(var i=0;i<obj.options.length;i++){     if(obj.options[i].innerHTML=="护照"){        obj.options[i].selected=true;        break;     }    } }</script></head><body><select id="test"><option>护照</option>  <option>港澳通行证</option>  <option>台湾通行证</option>  <option>台胞证</option>  <option>回乡证</option>  <option>国际海员证</option></select><a href="#" onclick="Test();">初始</a></body></html>
[解决办法]
HTML code
<asp:DropDownList ID="documentname_2" runat="server" >  <asp:ListItem>护照</asp:ListItem>  <asp:ListItem>港澳通行证</asp:ListItem>  <asp:ListItem>台湾通行证</asp:ListItem>  <asp:ListItem>台胞证</asp:ListItem>  <asp:ListItem>回乡证</asp:ListItem>  <asp:ListItem>国际海员证</asp:ListItem>  </asp:DropDownList><a>初始</a><script>$('#<%=documentname_2.ClientID%>>option:contains("护照")').attr('selected','true')</script> 

热点排行