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

查看:91
本文介绍了给定选项的文本/值,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天全站免登陆