日期:2014-05-17 浏览次数:20424 次
<form id="form1" runat="server"> <div> <asp:TextBox ID="txtFilterCity" runat="server" onkeyup="filterCity(this);"></asp:TextBox><br /> <asp:DropDownList ID="ddlCityList" runat="server"> </asp:DropDownList> </div> <script type="text/javascript"> var store = []; window.onload = function() { var citys = document.getElementById('ddlCityList'); for (var i = 0; i < citys.options.length; i++) { var city = { id: citys.options[i].value, name: citys.options[i].text }; store.push(city); } } function filterCity(o) { var citys = document.getElementById('ddlCityList'); citys.options.length = 0; if (o.value != '') { for (var j = 0; j < store.length; j++) { if (store[j].name.indexOf(o.value) >= 0) { var option = new Option(); option.value = store[j].id; option.text = store[j].name; citys.options.add(option); } } } else { for (var j = 0; j < store.length; j++) { var option = new Option(); option.value = store[j].id; option.text = store[j].name; citys.options.add(option); } } } </script> </form>