web standard/script2010. 3. 22. 14:02
/* =======================================================================
ㅁ펼침메뉴 클래스
==========================================================================*/

// 매뉴
function runMenuClick(callid,params)
{
 new display.ApmSoftNet.MENU(callid,params);
}

var display = {};
display.ApmSoftNet = {};


// method : function, params= 'id=menu1&cnt=2'
display.ApmSoftNet.MENU = function(method, params)
{
    this.call        = method;
    this.apmParams    = (params == null || params == '') ? null : params;
    this.send();
}


display.ApmSoftNet.MENU.prototype =
{
    send : function ()
    {
        var Vars = new Array();
       
        // params 배열로 정리
        var getVar1 = this.apmParams.split('&');
        for(var i=0; i<getVar1.length; i++)
        {       
            rltVar1 = getVar1[i];
            var getVar2 = rltVar1.split('=');
            // val str array
            nid = getVar2[0];
            nva = getVar2[1];
            Vars[nid] = nva;
        }
       
        switch(this.call)
        {
            case 'ShowNHide' :    this.menuShowNHide (Vars['id']);
            break;
            case 'OneDisplay' : this.menuOneDisplay (Vars['name'],Vars['id'],Vars['cnt']);
            break;
        }
    },
   
   
    /* [ 여러개의 목록을 펼치고 닫을 수 있는 방식 ]
       
      <table>
           <tr><td>    <a href="#" onClick="javascript:runMenuClick('ShowNHide','id=showmenu1');">메뉴 1</a>    </td></tr>
           <tr id="showmenu1" style="display:none;"><td>  메뉴1 내용  </td></tr>
      </table>

    */
    menuShowNHide : function (id)
    {
        runid = document.getElementById(id);
        if (runid.style.display=='none'){
            runid.style.display='block';
            document.getElementById('img_arrow').src='images/bar_title_up.gif';
            }
        else{
            runid.style.display='none';
            document.getElementById('img_arrow').src='images/bar_title_down.gif';
            }
    },
   
   
    /* [ 여러개 목록 중에서 하나만 펼쳐지도록 하는 방식 ]
     
      <table>
           <tr><td>    <a href="#" onClick="javascript:runMenuClick('OneDisplay','name=menu&id=menu1&cnt=2');">메뉴 1</a>    </td></tr>
           <tr id="menu1" style="display:none;"><td>  메뉴1 내용  </td></tr>
      </table>
      name : 아이디공통명, id : 고유아이디, cnt : 카운트
    */
    menuOneDisplay : function(name,id,cnt)
    {   
        var thisid = '';
        for(var i=1; i<=cnt; i++)
        {
            thisid = name+''+i;
            if( thisid == id ){ document.getElementById(thisid).style.display='block'; }
            else{ document.getElementById(thisid).style.display='none'; }
        }
    }
}
Posted by 수라