/**************************************************************************
*
* Function: toggleVis
*
* Description: Following Function hides and expands the main column.
*
*
***************************************************************************/
// Set the default "show" mode to that specified by W3C DOM
// compliant browsers
var showMode = 'table-cell';
// However, IE5 at least does not render table cells correctly
// using the style 'table-cell', but does when the style 'block'
// is used, so handle this
if (document.all) showMode='block';
// This is the function that actually does the manipulation
var States = { };
function toggleVis(col){
if (!States[col] || States[col].IsOpen == null)
{
States[col] = {isOpen : true}; // This assumes the cell is already shown
//States[col] = {isOpen : false}; // This assumes the cell is already hidden
}
//mode = States[col].IsOpen ? showMode : 'none';
mode = States[col].IsOpen ? 'none' : showMode; //starts from closed, next click need open
cells = document.getElementsByName(col);
for(j = 0; j < cells.length; j++) cells[j].style.display = mode;
States[col].IsOpen = !States[col].IsOpen;
}
이 함수는 html 테이블의 열을 숨기고 표시합니다. 이 함수를 호출하면 객체 상태가 그에 따라 토글되고, 확장되면 true, 숨겨 지거나 none이면 false로 설정됩니다. 함수가 한 번 실행 된 후 다시 호출 될 때이 함수에서 사용할 수 있도록 상태의 마지막 상태를 저장하는 것은 무엇입니까? 객체 상태 {}가 전역 변수로 선언 되었기 때문입니까?글로벌 자바 스크립트 개체는 상태를 어떻게 저장합니까?
그래서 함수에서 조작되었지만 상태가 "States [col] .IsOpen =! States [col] .IsOpen;"함수의 끝에서 전환 될 때 globa에 영향을 미치지 않으면 다음에 호출 할 때 함수의 맨 위에 무엇이 있는지 어떻게 알 수 있습니까? –
함수 내부에서 상태를 재정의하지 않으므로 전역 변수에 영향을 미칩니다. – AKX