为什么列表框选中的索引发生了变化?

时间:2013-11-18 09:21:27

标签: c# javascript asp.net

我已经为javascript个项目编写了一个sortlistbox方法,从某种意义上说,我在文本框中输入的项目会突出显示。

但是当我点击突出显示的项目时,它不会被选中。为什么呢?
selectedIndexchanged无效。

这是我的javascript代码:

 function SearchList() {
         var l = document.getElementById("<%= LBox.ClientID %>");
         var tb = document.getElementById("<%= txtDepartments.ClientID %>");
         if (tb.value == "") {
             ClearSelection(l);
         }
         else {
             for (var i = 0; i < l.options.length; i++) {
                 if (l.options[i].value.toLowerCase().match(tb.value.toLowerCase())) {
                     l.options[i].selected = true;

                     return false;
                 }
                 else {
                     ClearSelection(l);
                 }
             }
         }
     }

     function ClearSelection(l) {
         l.selectedIndex = -1;
     }

1 个答案:

答案 0 :(得分:0)

执行此操作,然后在内部调用您的函数,您需要引用jquery库

 $(document).ready(function() {    
            $('#' + '<%= DropdownName.ClientID %>').change(function() {
                      // Call function here...
               });

            });