如何从下拉列表中删除所选项目(使用Jquery) [英] How to remove a selected item from a dropdown list (Using Jquery)

查看:97
本文介绍了如何从下拉列表中删除所选项目(使用Jquery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从HTML下拉列表中删除选项标签中的一个或多个选定项(使用Jquery).

How to remove one or more selected items in option tag, from a HTML dropdown list (Using Jquery).

要从组合框中删除整个选项,我们可以使用下面的Jquery语句.

For removing entire options from a combo box we can use the below Jquery statement.

$(#cmbTaxIds> option").remove();

$("#cmbTaxIds >option").remove();

假设以下HTML代码位于aspx文件中.

Assuming the below HTML code in aspx file.

            <select id="cmbTaxID" name="cmbTaxID" style="width: 136px; display: none" tabindex="10" disabled="disabled">
                <option value="0"></option>
                <option value="3"></option>
                <option value="1"></option>
            </select>

如果我只想删除中间值,那么相同的语法应该是什么(使用Jquery)?

If I want to remove only the middle value, then what should be the syntax for the same (using Jquery)?

推荐答案

使用 eq 选择器.

Use the eq selector.

var index = $('#cmbTaxID').get(0).selectedIndex;
$('#cmbTaxID option:eq(' + index + ')').remove();

这是最好的方法,因为它基于索引,而不是基于任意值.

This is the best way to do it because it's index-based, not arbitrary value-based.

这篇关于如何从下拉列表中删除所选项目(使用Jquery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆