第一種效果
(帶自動匹配)這個效果再之前的的博客里面已經講到過了,還沒有看過的小伙伴可以移步→ http://www.cnblogs.com/zhangxiaoyong/p/5763432.html
第二種效果
今天主要講第二種效果,也比較簡單,先看下效果
實現
頁面部分
1 <form runat="server"> 2 <asp:DropDownList ID="DropDownList" runat="server" Width="180px" AutoPostBack="false" 3 Style="position: absolute;" onchange="SearchChange();"> 4 </asp:DropDownList> 5 6 <iframe id="DivShims" src="javascript:false;" scrolling="no" frameborder="0" style="position: absolute; 7 height: 20px;" width="158px"></iframe> 8 <input type="text" id="txtCName" runat="server" style="width: 158px; position: absolute;" /> 9 </form>
js部分
1 <script type="text/javascript"> 2 function SearchChange() { 3 var ddl = document.getElementById("DropDownList"); 4 var index = ddl.selectedIndex; 5 var Value = ddl.options[index].value; //獲取選中下拉列表的值 6 $("#txtCName").val(Value);//將選中的值賦值給input 7 } 8 </script>
后台測試代碼
1 List<string> list = new List<string>() 2 { 3 "湖北武漢", "湖北咸寧", "湖北孝感", "湖北安陸", "湖北恩施" 4 }; 5 foreach (var item in list) 6 { 7 DropDownList.Items.Add(item); 8 }