本文介绍了jQuery:如果select具有选项1,则显示div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,所以这个对我来说很棘手...
ok so this one was tricky for me...
我有一个动态创建的下拉菜单,如果下拉菜单中有"Other"选项,我想显示div #optionalmess
i have a dynamically created drop down and if the option "Other" is in that drop down i want to show div #optionalmess
<select class="VariationSelect" style="width: 95px;">
<option value="">Select Size</option>
<option value="1">Example</option
<option value="21">Other</option>
</select>
因此,如果.variationselect包含选项其他"(或值="21"),则显示#optionalmess
so if .variationselect contains the option "Other" (or value="21") show #optionalmess
如果下拉菜单中未包含其他"(值="21"),我想隐藏#optionalmess
if "other" (value="21") is not in the drop down, i want to hide #optionalmess
我在正确的轨道上,但是在编写它时是新手..
im on the right track but im a noob when it comes to writing it..
请帮助! =)
推荐答案
You can use the contains selector, in conjunction with toggle() for this:
$('#optionalmess').toggle(
$(".VariationSelect option:contains('Other')").length > 0
);
这篇关于jQuery:如果select具有选项1,则显示div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!