2016-09-27 106 views
0

我有2 checkboxes,當點擊應該隱藏/取消隱藏divs使用div.style.display「塊」:「無」隱藏/取消隱藏基於2複選框

  • 在初始頁面加載時,如果fundingAvailable = false上傳應該隱藏。 (見圖像)

enter image description here


  • 當用戶點擊Special Handling複選框,則上傳應hidden。 (見圖像)

enter image description here


  • 當用戶點擊Override Funding複選框,fundingAvailable = false,上載應shown。 (見圖片)

enter image description here


這是我到目前爲止有:

JSP

<INPUT TYPE="CHECKBOX" id="cbOverrideFunding" value="true" onclick="fundingAvailableWarning(<%=fundingAvailable%>)" > 
<INPUT TYPE="CHECKBOX" ID="cbSpecialHandling" value="true" onclick="specialHandlingWarning()"> 

<% if(!fundingAvailable) { %> 
    <TR> 
     <TD height="90" valign="top"><BR> 
     <div id="fundingAvailable" style="display: block"> 
      <b><i>The upload functionality has been disabled because the funding is missing.</i></b> 
     </div> 

     <div id="uploadFile"> 
     <INPUT name="File1" type="file" id="File1"/> 
     <a href="fileUpload()"> 
      <IMG src="../../images/UploadFile.gif" alt="Upload File"> 
     </a> 
     </div> 
<% } %> 
<% else { %> 
    <div id="uploadFile"> 
     <INPUT name="File1" type="file" id="File1"/> 
     <a href="fileUpload()"> 
     <IMG src="../../images/UploadFile.gif" alt="Upload File"> 
     </a> 
    </div> 

    <div id="uploadFileSpecialHandling" style="display: none"> 
     <b><i>The upload functionality has been disabled because of Special Handling. 
     </i></b> 
    </div> 
<% } %> 

的JavaScript

function specialHandlingWarning() 
{ 
    if(document.getElementById("fundingAvailable").checked) { 
     var div = document.getElementById("uploadFile"); 
     div.style.display = div.style.display == "none" ? "block" : "none"; 

     div = document.getElementById("uploadFileSpecialHandling"); 
     div.style.display = div.style.display == "none" ? "block" : "none"; 
    } 
} 

function fundingAvailableWarning(fundingAvailable) 
{ 
    if(!fundingAvailable) { 
     var div = document.getElementById("uploadFile"); 
     div.style.display = div.style.display == "none" ? "block" : "none"; 

     div = document.getElementById("fundingAvailable"); 
     div.style.display = div.style.display == "none" ? "block" : "none"; 
    } 
} 

我的問題是,這兩個div在一起玩不好。

如果我先選擇Special Handling,它將顯示Upload頁面並隱藏我的警告。

+0

你可以試試'unset'來代替'none'這裏=>'? 「block」:「none」;'? –

+0

@David R你的意思是在uploadFile div或全部? – Angelina

回答

0

我會控制一切通過CSS,所以你可以只需要改變你最父母元素的類名稱。