2013-11-28 2 views
1

foldout 함수는 완벽하게 작동하지만 두 번째 함수를 먼저 실행하여 다른 모든 요소를 ​​먼저 닫고 싶지만 무엇이 잘못되었는지는 알 수 없습니다. 도와 주셔서 감사합니다!윈도우 접기 및 다른 접기 코드

편집. 두 번째 함수가 작동하지 않거나 이미 열린 폼을 닫지 않는 것 같습니다.

편집. 답변 해 주셔서 감사합니다. 나는 내일을 더 읽고 모든 것을 시도 할 시간을 가질 것이다.

functions.js :

function foldout(fold) { 

    if (document.getElementById) { 
     var fold = document.getElementById(fold).style; 
      if (fold.display == "block") { 
       fold.display = "none"; 
      } else { 
       fold.display= "block"; 
      } 
    return false; 
    } else { 
    return true; 
    } 
}; 
function foldall() { 
    var foldall = document.getElementsByClassName('foldall'); 
     for(var i=0; i<foldall.length; i++) { 
      var foldthis = foldall[i]; 
     if (foldthis.display == "block") { 
      foldthis.display = "none"; 
      } 
     } 
}; 

page.php :

<a href="#" onclick="foldall('foldall'); return foldout('fold');"> </a> 
<form method="POST" style="display: none;" class ="foldall" id="fold"> 
</form 
+0

무엇이 잘못 되었습니까? 설명 해주십시오. – Bart

답변

0

에 한번 당신의 foldout 기능에서 foldall 함수를 호출 :

function foldall() { 
    var foldall = document.getElementsByClassName('foldall'); 
     for(var i=0; i<foldall.length; i++) { 
      var foldthis = foldall[i]; 
     if (foldthis.display == "block") { 
      foldthis.display = "none"; 
      } 
     } 
}; 

function foldout(fold) { 
    foldall(); // collapse everything 
    if (document.getElementById) { 
     var fold = document.getElementById(fold).style; 
     if (fold.display == "block") { 
      fold.display = "none"; 
     } else { 
      fold.display= "block"; 
     } 
     return false; 
    } else { 
     return true; 
    } 
}; 

그리고 당신의 onclick에서만 접어 넣은 전화 처리기 :

<a href="#" onclick="foldout('fold');"></a> 
<form method="POST" style="display: none;" class ="foldall" id="fold"></form>