我有這個if-else語句給了我奇怪的迴應......每當我先選擇「輸出」,以後沒有其他選擇可以出現... 僅供參考,我使用多選擇,所以我可以選擇和顯示儘可能多如我所願。如何爲jQuery做一個開關盒?
$('#outputText').hide();
$('#armCB').hide();
$('#outputCB').hide();
$('#zoneText').hide();
$('#counterText').hide();
$('#flagText').hide();
$('#sensorText').hide();
('#select-choice-1').change(function(){
if ($('#output').is(':selected')){
$('#outputText').show();
}
else if ($('#arm').is(':selected')){
$('#armCB').show();
}
else if ($('#zone').is(':selected')){
$('#zoneText').show();
}
else if ($('#counter').is(':selected')){
$('#counterText').show();
}
else if ($('#flag').is(':selected')){
$('#flagText').show();
}
else if ($('#sensor').is(':selected')){
$('#sensorText').show();
}
else{
$('#outputText').hide();
$('#armCB').hide();
$('#zoneText').hide();
$('#counterText').hide();
$('#flagText').hide();
$('#sensorText').hide();
}
在我的if-else語句中是否有錯誤?或者我必須在這裏使用Switch case語句嗎?如果是這樣,我該怎麼做?
HTML:
<div id="display" style=" clear:both">
<div class="left" style="float:left; width:48%">
<div data-role="fieldcontain">
<label for="select-choice-1" class="select">Select Category</label>
<select name="select-choice-1" id="select-choice-1" data-native-menu="false" data-mini="true" multiple="multiple" size="2">
<option value="arm" id="arm">Arm</option>
<option value="zone" id="zone">Zone Input</option>
<option value="output" id="output">Output</option>
<option value="counter" id="counter">Counter</option>
<option value="flag" id="flag">Flag</option>
<option value="sensor" id="sensor">Sensor</option>
</select>
</div>
</div>
<div class="right" style=" float: right; width:48%">
<div id="armCB">
<fieldset data-role="controlgroup">
<legend>Unit</legend>
<input type="checkbox" class="CB" name="armCB_1" id="armCB_1" class="custom" data-mini="true" />
<label for="armCB_1">Arming Status</label>
</fieldset>
</div>
<div id="outputText">
<p> Please enter an Output number and press "Add" button: </p>
<input style="background: white; color: black;" type="text" id="outputTextInput" value="">
<input type="submit" id="outputAdd" value="Add"/>
<input type="submit" id="outputRemove" value="Remove"/>
</div>
<div id="zoneText">
<p> Please enter a Zone number and press "Add" button: </p>
<input style="background: white; color: black;" type="text" id="zoneTextInput" value="">
<input type="submit" id="zoneAdd" value="Add"/>
<input type="submit" id="zoneRemove" value="Remove"/>
</div>
<div id="counterText">
<p> Please enter a counter number and press "Add" button: </p>
<input style="background: white; color: black;" type="text" id="counterTextInput" value="">
<input type="submit" id="counterAdd" value="Add"/>
<input type="submit" id="counterRemove" value="Remove"/>
</div>
<div id="flagText">
<p> Please enter a Flag number and press "Add" button: </p>
<input style="background: white; color: black;" type="text" id="flagTextInput" value="">
<input type="submit" id="flagAdd" value="Add"/>
<input type="submit" id="flagRemove" value="Remove"/>
</div>
<div id="sensorText">
<p> Please enter a Sensor number and press "Add" button: </p>
<input style="background: white; color: black;" type="text" id="sensorTextInput" value="">
<input type="submit" id="sensorAdd" value="Add"/>
<input type="submit" id="sensorRemove" value="Remove"/>
</div>
</div>
</div>
什麼是對上述的if..else的if..else問題? – 2013-04-22 05:25:42
@SJnawali這是一個多重選擇,如果我先選擇「輸出」,後來選擇的其他人將不會出現。 – yvonnezoe 2013-04-22 06:01:26