當我選擇了單選按鈕'Up'時,它將顯示'productionUp'跨度,當選擇單選按鈕'down'時,'productionUp'將隱藏, 'productionDown'跨度將顯示。當兩個選項都不顯示時隱藏2個跨度
當'Same'被選中時,我希望既可以隱藏,但我不確定我所做的是否是最有效的方式。下面是HTML代碼
<fieldset>
<legend>Production</legend>
<p>Was your production level in October versus September 2013....</p>
<input type="radio" name="production-level" value="Up">Up<br />
<input type="radio" name="production-level" value="Same">Same<br />
<input type="radio" name="production-level" value="Down">Down
<p>Note: PRODUCTION level meaning the level of overall production this month measured in units as compared to last month.</p>
<span id='productionUp' class='level'>
<p>Production - Reasons why it is up. Click as many as apply.</p>
<input type="checkbox" name="production-why-up" value="Increase in demand">Increase in demand <br/>
<input type="checkbox" name="production-why-up" value="Expected increase in demand">Expected increase in demand <br/>
<input type="checkbox" name="production-why-up" value="Fullfillment of past orders">Fulfillment of past orders <br/>
<input type="checkbox" name="production-why-up" value="Increased marketing activity">Increased marketing activity <br/>
Other: <input type="text" />
</span>
<span id='productionDown' class='level'>
<p>Production - Reasons why it is down. Click as many as apply.</p>
<input type="checkbox" name="production-why-down" value="Decrease in demand">Decrease in demand <br>
<input type="checkbox" name="production-why-down" value="Expected Decrease in demand">Expected Decrease in demand <br/>
<input type="checkbox" name="production-why-down" value="Technical difficulties in production">Technical difficulties in production <br/>
<input type="checkbox" name="production-why-down" value="Shortage in raw materials">Shortage in raw materials <br/>
Others: <input type="text" />
</span>
</fieldset>
的JavaScript代碼
$(document).ready(function(){
// Production Level
$("input[name = 'production-level']").click(function() {
var production = $(this).val();
var opposite = '';
if(production == 'Up') {
opposite = 'Down';
$("#production" + opposite).hide();
$("#production" + production).show();
}
else if (production == 'Down') {
opposite = 'Up';
$("#production" + opposite).hide();
$("#production" + production).show();
}
else {
$("#productionUp").hide();
$("#productionDown").hide();
}
});
});
如果你把在這一個眼神,你會認爲我選擇了隱藏他們兩人即使一個已經隱藏,我不能想到任何其他方式有效地隱藏選定的一個。請指教。
else {
$("#productionUp").hide();
$("#productionDown").hide();
}
使用兩個css類一個用於顯示和一個用於隱藏 –
它沒關係..它有什麼問題?你可以隨時檢查可見性,如果你想,但我不明白你爲什麼應該這樣做。 – Hardy