2012-06-27 78 views
0

我在一個框中列出了一個名稱,我想根據用戶輸入來篩選並篩選出不匹配的名稱。很像這個例子:http://www.somacon.com/p241.php。我是新來的Javascript,這是我的名字是如何顯示在對話框:在Javascript中篩選列表

<select id="authorSelectId" multiple="multiple" class="accordionSelect"> 
<c:forEach var="author" items="${dropDownValues.authorDisplayList}"> 
<option value="${author}">${author}</option> 
</c:forEach> 
</select> 

這是我的用戶輸入框:

<input onKeyUp="handleKeyUp(20);" type="text" id='functioninput' name="functioninput" VALUE="" style="font-size:10pt;width:34ex;"> 

我的代碼正確地叫我「handleKeyUp(20 )「 方法。但我不確定如何鏈接到「authorSelectId」名稱列表並通過基於「functionInput」文本的過濾器進行過濾。如果需要更多的代碼,我可以提供。任何幫助表示讚賞。

回答

0

你用得到authorSelectId參考:

var asi= document.getElementById("authorSelectId"); 

然後,您可以遍歷這樣的選項:

for (var i= 0; i < asi.options.length; ++i) { 
    var opt= asi.options[i]; 
    if (opt.selected) { 
     // do something... 
    } 
}