jQuery 从下拉列表中删除一个选项,给定选项的文本/值 [英] jQuery to remove an option from drop down list, given option's text/value

查看:20
本文介绍了jQuery 从下拉列表中删除一个选项,给定选项的文本/值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,并想从中删除一个选项,考虑到该特定选项的文本/值.是否可以使用 jQuery?就像'append'在下拉列表中添加一个选项一样,有没有删除选项的功能?

I have a drop down list and would like to remove an option from it, given the text/value of that particular option. Is it possible using jQuery? Just like 'append' which adds an option to the drop down list, is there a function to remove an option?

我尝试搜索它,但我得到的只是下拉列表中的整个选项集都被删除的示例,这不是我想要的.

I tried searching for it but all I got were examples where the entire set of options in the drop down list are removed, which is not what I seek.

干杯

推荐答案

$("option[value='foo']").remove();

或更好(如果页面中的选择很少):

or better (if you have few selects in the page):

$("#select_id option[value='foo']").remove();

这篇关于jQuery 从下拉列表中删除一个选项,给定选项的文本/值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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