0

我在一个框中有一个名称列表,我想根据用户输入过滤并过滤掉不匹配的名称。很像这个例子: http: //www.somacon.com/p241.php。我是 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”文本的名称进行过滤。如果需要更多代码,我可以提供。任何帮助表示赞赏。

4

1 回答 1

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...
    }
}
于 2012-06-27T17:37:37.523 回答