禁用(disabled)/启用所有子控件

ContractedBlock.gif ExpandedBlockStart.gif Code
 1//改变父控件中所有子控件的ENABLED  
 2//parentID 为父控件或父控件ID  
 3//disabled为是否禁用true 为禁用,false 为可用  
 4//filter为不更改disabled而更改readOnly的以|分隔的控件ID列表  
 5function SetChildControlsStatus(parentID,disabled,filter)  
 6ExpandedBlockStart.gifContractedBlock.gif{  
 7    var parent;  
 8    if(typeof(parentID)=="undefined")  
 9ExpandedSubBlockStart.gifContractedSubBlock.gif    {return;}  
10    if(typeof(parentID)=="string")  
11ExpandedSubBlockStart.gifContractedSubBlock.gif    {  
12        parent=document.getElementById(parentID);  
13    }
  
14    else  
15ExpandedSubBlockStart.gifContractedSubBlock.gif    {  
16        parent=parentID;  
17    }
  
18    var i=0;  
19    for(i=0;i<parent.childNodes.length;i++)  
20ExpandedSubBlockStart.gifContractedSubBlock.gif    {  
21        var m_TagName=parent.childNodes[i].tagName  
22        if(m_TagName)  
23ExpandedSubBlockStart.gifContractedSubBlock.gif        {  
24            m_TagName = m_TagName.toUpperCase();  
25        }
  
26        else  
27ExpandedSubBlockStart.gifContractedSubBlock.gif        {  
28            continue;  
29        }
  
30        if(m_TagName=="INPUT"||m_TagName=="SELECT"||m_TagName=="TEXTAREA")  
31ExpandedSubBlockStart.gifContractedSubBlock.gif        {  
32            if(filter && filter.indexOf(parent.childNodes[i].id) > -1)  
33ExpandedSubBlockStart.gifContractedSubBlock.gif            {  
34                parent.childNodes[i].readOnly=disabled;  
35            }
  
36            else  
37ExpandedSubBlockStart.gifContractedSubBlock.gif            {  
38                parent.childNodes[i].disabled=disabled;  
39            }
  
40        }
  
41        if(parent.childNodes[i].childNodes)  
42ExpandedSubBlockStart.gifContractedSubBlock.gif        {  
43            if(filter)  
44ExpandedSubBlockStart.gifContractedSubBlock.gif            {  
45                SetChildControlsStatus(parent.childNodes[i],disabled,filter);  
46            }
  
47            else  
48ExpandedSubBlockStart.gifContractedSubBlock.gif            {  
49                SetChildControlsStatus(parent.childNodes[i],disabled);  
50            }
  
51        }
  
52    }
//for  
53}

转载于:https://www.cnblogs.com/shendsun/archive/2008/08/18/1270257.html

你可能感兴趣的:(禁用(disabled)/启用所有子控件)