简体   繁体   English

使用 jQuery 从 Telerik 下拉列表中删除项目

[英]Removing Items from Telerik Drop down list using jQuery

I know how to add items to a telerik ddl using jquery, but how do I remove values?我知道如何使用 jquery 向 Telerik ddl 添加项目,但如何删除值?

Thanks in advance提前致谢

Here is a demo of RadComboBox with Add/Remove/Disable Items ...这是带有添加/删除/禁用项目的 RadComboBox 的演示......

http://demos.telerik.com/aspnet-ajax/combobox/examples/programming/addremovedisableitemsclientside/defaultcs.aspx http://demos.telerik.com/aspnet-ajax/combobox/examples/programming/addremovedisableitemsclientside/defaultcs.aspx

Basically - you need to first get combo box itself.基本上 - 您需要首先获得组合框本身。 Here is the code:这是代码:

var combo = $find("<%= RadComboBox1.ClientID %>");

Lets assume you want to remove the currently selected item in the combo box.假设您要删除组合框中当前选定的项目。 You will need to first grab the item like below:您需要先获取如下项目:

var comboItem = combo.get_selectedItem();

Now to remove the above item from the combo box, we first need to get the items collection and then call the remove method on the collection by passing the item we want to remove.现在要从组合框中删除上述项目,我们首先需要获取项目集合,然后通过传递我们要删除的项目来调用集合上的 remove 方法。 Here is the code snippet for the same:这是相同的代码片段:

if(comboItem)
        { 
            combo.trackChanges();
            combo.get_items().remove(comboItem);
            combo.commitChanges();
        }

Here is another example of removing an item from the combobox - this time we search the item by its name:这是从组合框中删除项目的另一个示例 - 这次我们按名称搜索项目:

var combo = $find("<%= RadComboBox1.ClientID %>");
var items = combo.get_items();
var comboItem = combo.findItemByText("Paris");
combo.trackChanges();
items.remove(comboItem); 
combo.commitChanges();

Here is the documentation for the client side API of ComboBox (disclaimer: I'm part of Telerik):这是 ComboBox 客户端 API 的文档(免责声明:我是 Telerik 的一部分):

http://www.telerik.com/help/aspnet-ajax/combobox-client-side-radcomboboxitemcollection.html http://www.telerik.com/help/aspnet-ajax/combobox-client-side-radcomboboxitemcollection.html

this will remove all items from dropdown .这将从下拉列表中删除所有项目。

var combo2 = $find('<%= drp_Year.ClientID%>'); var combo2 = $find('<%= drp_Year.ClientID%>');
combo2.get_items().clear() combo2.get_items().clear()

https://a2zcode.com/Removing-Items-from-Telerik-Drop-down-list-using-jQuery https://a2zcode.com/Removing-Items-from-Telerik-Drop-down-list-using-jQuery

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 jQuery 从下拉列表中删除除第一个之外的所有值 - Removing all values but the first from a drop down list using jQuery JQuery从asmx web服务返回一系列下拉列表项,然后绑定到下拉列表? - JQuery return an array of drop down list items from asmx web service and then bind to drop down list? jQuery单击事件的下拉列表项 - Jquery click event for drop down list items JQuery Change下拉列表项 - JQuery Change Drop Down List Items 一旦我使用经典的asp,jquery和ajax从第一个下拉列表中选择一个值,如何显示所选项目的表格? - How to display a table of selected items once I select a value from the first drop down list using classic asp, jquery and ajax? 使用jQuery从下拉列表中获取选定的文本 - Get selected text from a drop-down list using jQuery 从jsp.net中的列表使用级联下拉列表 - Cascading drop down using jquery from list in asp.net 使用文本框内的jQuery填充下拉列表 - Populate Drop Down List using jquery from textbox 需要使用JQuery将数据从下拉列表传递到表 - Need to Pass Data From Drop Down List to Table using JQuery 使用jQuery /纯jscript从HTML下拉列表(选择下拉列表时下拉列表)中获取事件数据 - Get event data from an HTML drop down list (the list that drops down when a drop down list is selected) using jQuery / plain jscript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM