如果在下拉列表中选择了特定值,我会尝试隐藏 div。我在用着
$(this).next('.selectNos').hide();
但由于某种原因它无法完成这项工作。请有人指出我做错了什么?
$(document).ready(function() {
$('#addCondition').on('change','.conOperatorC', function(e){
if ($('option:selected',this).text() == "In" || $('option:selected',this).text() == " Not In") {
alert($('option:selected',this).text());
$(this).next('.selectNos').hide();
}
else {
$(this).next(':select').hide();
}
});
$('.conOperatorC').trigger('change');
});
<div id="addCondition">
<select id="conOperator0" name="conOperator0" class="standard_select conOperatorC" style="width:147px;">
<option>blah</option><option>
<option>Contains</option>
<option>In</option>
<option>Not In</option>
</select>
<input type="text" id="conValue0" name="conValue0" class="short_input" value="" style="width:147px;">
<div class="selectNos">
<select id="conValuedd0" multiple="multiple" size="5" style="display: none; ">
<option value="option1">blah</option>
<option value="option2">blah</option>
</select>
<button type="button" class="ui-multiselect ui-widget ui-state-default ui-corner-all" aria-haspopup="true" tabindex="0" style="width: 225px; "><span class="ui-icon ui-icon-triangle-2-n-s"></span><span>Please Select</span></button>
</div>
</div>
最佳答案
方法next
精确选择next 元素。您最好使用siblings
:
$(this).siblings('.selectNos').hide();
顺便说一句,为了在您的情况下获取所选值,您可以使用 this.value
而不是 $('option:selected', this).text()
.
关于javascript - 当我试图隐藏 div 时,Jquery .next() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11311447/