如何在下拉事件更改时使用jquery清除或清空列表框

use*_*194 3 javascript jquery jquery-ui

任何正文都可以帮我解决如何在下拉事件更改时清除列表框中的项目.

$(function () {
        $("#ddlLevelColumn").change(function () {
            $("#lstCodelist") ------ I need to clear this listbox1
            $("#lbxSelectedItems")--------------- need to clear list box 2

        });
    });

 <%:Html.ListBox("lstCodelist", Model.CodeListDefaultValue, new { style = "width:99%;height:297px;" })%>
<%:Html.ListBox("lbxSelectedItems", Model.AffectedCodeListboxData, new { style = "width:99%;height:297px;color:blue;" })%>
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助..

Zee*_*der 15

空()

$("#lstCodelist").empty()
$("#lbxSelectedItems").empty()
Run Code Online (Sandbox Code Playgroud)


Bra*_*tie 5

您可以删除所有条目(或同时应用过滤器):

$('#listBoxId > option').remove();           // all options
$('#listBoxId > option[val!=""]').remove(); // keep non-empty values
Run Code Online (Sandbox Code Playgroud)

你想要的是什么?我相信更简单:

$('#listBoxId').empty();
Run Code Online (Sandbox Code Playgroud)

应该也可以.

工作演示:http://jsfiddle.net/jEWe6/