Javascript 如何在下拉事件更改时使用jquery清除或清空列表框
任何人都可以帮助我清除下拉事件更改列表框中的项目Javascript 如何在下拉事件更改时使用jquery清除或清空列表框,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,任何人都可以帮助我清除下拉事件更改列表框中的项目 $(function () { $("#ddlLevelColumn").change(function () { $("#lstCodelist") ------ I need to clear this listbox1 $("#lbxSelectedItems")--------------- need to clear list box 2 });
$(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;" })%>
感谢您的帮助。您可以删除所有条目或应用过滤器:
$('#listBoxId > option').remove(); // all options
$('#listBoxId > option[val!=""]').remove(); // keep non-empty values
这就是你想要的?我认为更简单的是:
$('#listBoxId').empty();
也应该有效
工作演示:
我想。空的是你要找的
从DOM中删除匹配元素集的所有子节点
您可以使用以下方法清除select html元素:
var clear = function() {
$("#lstCodelist").empty().append('<option value="whatever">Wait for reload</option>');
$("#lbxSelectedItems").empty().append('<option value="whatever">Wait for reload</option>');
});
您也可以尝试这两种方法中的任何一种 $'RolesListAvailable'.html; 或 $'RolesListAssigned'。为空; 试试这个
$('#listBoxId').empty();
请包括相关的HTML,而不是服务器端代码。
$('#listBoxId').empty();