我正在根据另一个组合框重置组合框。我有 2 个组合框,当我选择 01
时然后second combo
已启用,并且当我从2nd combo
中选择一个选项时然后是text box
出现,当我从 first combo
中选择“请选择”时然后2nd combo
是自动重置(禁用),但为什么该文本框没有消失?
当从第二个组合中选择除第一个选项之外的选项时,我将填充一个文本框,例如:
$(function() {
//This hides all initial textboxes
$('label').hide();
$('#secondcombo').change(function() {
//This saves some time by caching the jquery value
var val = $(this).val();
//this hides any boxes that the previous selection might have left open
$('label').hide();
//This just opens the ones we want based off the selection
switch (val) {
case 'option1':
case 'option4':
case 'other':
$('#label1').show();
break;
}
});
//I'm not really sure why these are here
$("input").focus(function() {
$(this).next("span").fadeIn(500);
}).blur(function() {
$(this).next("span").fadeOut(1000);
});
});
HTML
<select id='firstcombo'>
<option value="">please select</option>
<option value="01">01</option>
<option value="02">02</option>
</select>
<select id='secondcombo' disabled="true">
<option value="_">- select -</option>
<option value="option1">data</option>
<option value="option2">data</option>
</select>
<label id="label1" for="option1">
<input type="text" id="option1" />
</label>
最佳答案
这并不是隐藏,因为在此代码中没有第一个组合的事件。
您可以使用下面的代码来隐藏它
<select id='firstcombo' onchange="jQuery('label#label1').hide();">
<option value="">please select</option>
<option value="01">01</option>
<option value="02">02</option>
</select>
这对你有用。
关于javascript - 重置组合框时隐藏文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9544253/