這裏是我的JSP代碼片段,它使用Spring MVC的如何在jQuery中實現If ... else結構?
<form:select path="noOfBankDetails" id = "noOfBankDetails">
<form:option value="0">0</form:option>
<form:option value="1">1</form:option>
<form:option value="2">2</form:option>
<form:option value="3">3</form:option>
<form:option value="4">4</form:option>
</form:select>
<!-- All the following divs are hidden -->
<div id = "firstBankDetail">
<div id = "secondBankDetail">
<div id = "thirdBankDetail">
<div id = "fourthBankDetail">
這裏是我的jQuery的片段,顯示在下拉noOfBankDetails改變
$("#noOfBankDetails").change(function(){
$("#firstBankDetail").show();
$("#secondBankDetail").show();
$("#thirdBankDetail").show();
$("#fourthBankDetail").show();
});
它完美罰款所有div ......但我想實現不同的東西 僞它是這樣的
IF noOfBankDetails IS 0 THEN
Show none of divs
ELSE IF noOfBankDetails IS 1 THEN
Show div firstBankDetail
ELSE IF noOfBankDetails IS 2 THEN
Show div firstBankDetail
Show div secondBankDetail
and so on..
我應該怎樣着手做這jQuery的。我是jQuery的初學者。請提供一些指導。
你已經制定了邏輯。只需將它們逐行轉換成jquery代碼即可。多數民衆贊成..後擔心優化 – karthikr