消息1:验证(ASP.Net):属性'onkeyup'不是元素'TextBox'的有效属性。 E:\ ABC \ ABCD.aspx 83 66 ABCD
我想要下拉列表根据TextBox中输入的值更改显示列表。我已经为它编写了以下查询
var ddlText, ddlValue, ddl, lblMesg;
function CacheItems() {
ddlText = new Array();
ddlValue = new Array();
ddl = document.getElementById("=STCDropDownList.ClientID");
lblMesg = document.getElementById("=Label1.ClientID");
for (var i = 0; i < ddl.options.length; i++) {
ddlText[ddlText.length] = ddl.options[i].text;
ddlValue[ddlValue.length] = ddl.options[i].value;
}
}
window.onload = CacheItems;
function FilterItems(value) {
ddl.options.length = 0;
for (var i = 0; i < ddlText.length; i++) {
if (ddlText[i].toLowerCase().indexOf(value) != -1) {
AddItem(ddlText[i], ddlValue[i]);
}
}
lblMesg.innerHTML = ddl.options.length + " item(s) found.";
if (ddl.options.length == 0) {
AddItem("No item found.", "");
}
}
function AddItem(text, value) {
var opt = document.createElement("option");
opt.text = text;
opt.value = value;
ddl.options.add(opt);
}
以下是我正在使用的Textbox和DropDownlist。
<asp:TextBox ID="STCTextBox" runat="server" onkeyup="FilterItems(this.value)"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style3">Service Tax Code</td>
<td class="auto-style3">
<asp:DropDownList ID="STCDropDownList" runat="server" AutoPostBack="True" DataSourceID="STCSqlDataSource" DataTextField="ServiceTaxCode" DataValueField="ServiceTaxCode"></asp:DropDownList>
<asp:Label ID="Label1" runat="server" Text="Entered Comm Code Already Registered" Visible="False"></asp:Label>
答案 0 :(得分:1)
答案 1 :(得分:0)
从我看到的内容
用此替换函数FilterItem可以提供帮助
var txtBox=document.getElementById("=STCTextBox.ClientID");
txtBox.onkeyup=function() {
var value=txtBox.value;
ddl.options.length = 0;
for (var i = 0; i < ddlText.length; i++) {
if (ddlText[i].toLowerCase().indexOf(value) != -1) {
AddItem(ddlText[i], ddlValue[i]);
}
}
lblMesg.innerHTML = ddl.options.length + " item(s) found.";
if (ddl.options.length == 0) {
AddItem("No item found.", "");
}
}
答案 2 :(得分:0)
而是使用jQuery:
$("#id").keyup(function(){<br/>
// Your Code <br/>
});