简体   繁体   English

jQuery:按值选择选项元素

[英]jQuery: Selecting option elements by their value

I'd like to remove a specific option from some select boxes (all with the same values) if their value is "1". 如果它们的值为“1”,我想从某些选择框中删除特定选项(所有选项都具有相同的值)。 The problem is, I'm having difficulty filtering elements down to that specific value. 问题是,我很难将元素过滤到特定值。

At the moment, the closest I've got is 目前,我最接近的是

$('.demoClass').find('option:contains(1)').remove();

but there are two problems. 但有两个问题。 Firstly, this seems to iterate over the (displayed) contents of the option, not its value...and secondly, it seems to return true the contents contain that value, as opposed to being that value. 首先,这似乎遍历选项的(显示)的内容,而不是它的价值......其次,它似乎返回true内容包含价值,而并非该值。 (Eg contains(1) will return true for (1, 10, 11, 12)...when I want it to return true for "1" only) (例如,包含(1)将为(1,10,11,12)返回true ...当我希望它仅为“1”返回true时)

In short, what I'm looking to do is find the timeslot option with value X inside all select boxes of class ".demoClass" and remove them. 简而言之,我要做的是在类“.demoClass”的所有选择框中找到值为X的时间段选项并删除它们。 Any suggestions appreciated. 任何建议赞赏。

Try this... 尝试这个...

$('.demoClass').find('option[value="1"]').remove();

This utilizes the Attribute Equals Selector 这利用了属性等于选择器

来自jquery

尝试这个:

$('.demoClass').find('option[value=1]').remove();

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM