我正在重置基於另一個組合框的組合框。我有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>
這是最簡單的方法...如果你想要做的事更多的功能,這個然後綁定這個像第二個組合 – 2012-03-03 07:13:05
感謝Shivam,但如果我有一個以上的標籤,該標籤是label1,label2,label3 ...那麼我該如何編輯這個'''jQuery('label#label1')。hide();'? – Tom 2012-03-03 07:18:04
@tom:你只能使用'$('label')。hide )',如果你不知道你的標籤都抱着IDS。 – codef0rmer 2012-03-03 07:22:08