/**************************************************************************
*
* 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;如果爲隱藏或無,則爲false。函數執行一次後,什麼保存狀態的最後一個狀態,以便在再次調用時可以在此函數中使用它?是否因爲對象States {}被聲明爲全局?全局Javascript對象如何保存狀態?
因此,如果它在函數中被操縱但不影響球體,當狀態在函數「States [col] .IsOpen =!States [col] .IsOpen;」 它是如何知道下一次調用函數頂部的是什麼? – 2009-07-08 21:55:59
就你而言,它會影響全局,因爲你不在函數內部重新定義狀態。 – AKX 2009-07-09 14:59:44