根据onKeyUp函数中的输入控制值填充列表框

fill ListBox according to input control value in onKeyUp function

本文关键字:填充 列表 控制 输入 onKeyUp 函数 根据      更新时间:2023-09-26

我有一个列表框控件

 <asp:ListBox ID="ListBox1" runat="server">
                            <asp:ListItem Value="1" Text="XYZ" />
                            <asp:ListItem Value="0" Text="XYZD" />
                            <asp:ListItem Value="-1" Text="D" />
 </asp:ListBox>

输入 :

<input id="listBoxFilterTextBox" type="text" onkeyup="FilterListBox()"

js 函数 :

 function FilterListBox() {
        var listBox = Get('ListBox1');
        var textBox = Get('listBoxFilterTextBox');
        for (i = 0; i < listBox.options.length; i++) {
            if (listBox.options[i].text.toLowerCase().indexOf(textBox.value.toLowerCase()) != -1) {
                listBox.options[i].style.display = "";
            } else {
                listBox.options[i].style.display = "none";
            }
        }
         function Get(id) {
        return document.getElementById(id);
         }
当我输入"

X"输入控制时,它带来了"XYZ","XYZD"。它可以正常工作 火狐 和 铬.但是在IE中,它无法正常工作。如何解决这个IE问题?

提前感谢...

你不能在 IE 中使用 CSS 在 SELECT 中隐藏 OPTION。而是添加第二个具有所有需要选项的列表框源,并仅从列表框源复制到列表框源,仅满足条件的选项。