강의 컨설팅 트레이닝 무료진단 무료책자 마케팅편지 마케팅정보공유 다이어리 서비스제휴 고객센터

체크박스 트리메뉴
작성자 : 99 단국강토
등록날짜 : 2009.02.03 10:18
3,788

<HTML>
<HEAD>
    <TITLE>BLUE-B</TITLE>
<style>
ul.checktree, ul.checktree ul {
list-style-type: none;
padding: 0;
margin: 0;
font: 10px sans-serif;
}

ul.checktree li {
background: url(http://www.blueb.co.kr/SRC/javascript/image3/node.gif) no-repeat;
margin: 0;
padding: 0 0 0 16px;
cursor: default;
}
ul.checktree li.last {
background-image: url(http://www.blueb.co.kr/SRC/javascript/image3/node-last.gif);
}
ul.checktree li.plus {
background-image: url(http://www.blueb.co.kr/SRC/javascript/image3/plus.gif);
}
ul.checktree li.plus-last {
background-image: url(http://www.blueb.co.kr/SRC/javascript/image3/plus-last.gif);
}
ul.checktree li.minus {
background-image: url(http://www.blueb.co.kr/SRC/javascript/image3/minus.gif);
}
ul.checktree li.minus-last {
background-image: url(http://www.blueb.co.kr/SRC/javascript/image3/minus-last.gif);
}

ul.checktree span.count {
text-indent: 5pt;
color: #999;
font-style: italic;
}
</style>
<script type="text/javascript">
function CheckTree(myName) {
    this.myName = myName;
    this.root = null;
    this.countAllLevels = false;
    this.checkFormat = '(%n% checked)';
    this.evtProcessed = navigator.userAgent.indexOf('Safari') > -1 ? 'safRtnVal' : 'returnValue';
         CheckTree.list[myName] = this;
};
CheckTree.list = [];


// Called onload, this sets up a reference to the 'root' node and hides sublevels.
CheckTree.prototype.init = function() { with (this)
{
if (!document.getElementById) return;
root = document.getElementById('tree-' + myName);
if (root)
{
  var lists = root.getElementsByTagName('ul');
  for (var ul = 0; ul < lists.length; ul++)
  {
   // Hide all UL sublevels under the root node, and assign them a toggle/click methods.
   lists[ul].style.display = 'none';
   lists[ul].treeObj = this;
   lists[ul].setBoxStates = setBoxStates;

   var fn = new Function('e', 'this.setBoxStates(e)');
   // Grr, workaronud another Safari bug.
   if (lists[ul].addEventListener && navigator.vendor != 'Apple Computer, Inc.')
   {
    lists[ul].addEventListener('click', fn, false);
   }
   else lists[ul].onclick = fn;
  }

  // Now do a similar event capture setup for the 'root' node.
  root.treeObj = this;
  root.setBoxStates = setBoxStates;
  if (root.addEventListener && navigator.vendor != 'Apple Computer, Inc.')
  {
   root.addEventListener('click', new Function('e', myName + '.click(e)'), false);
  }
  else root.onclick = new Function('e', myName + '.click(e)');
  // Trigger a quick state update, to set the counters for each level.
  root.setBoxStates({}, true, true);

  // Now go through and assign plus/plus-last classes to the appropriate <LI>s.
  var nodes = root.getElementsByTagName('li');
  for (var li = 0; li < nodes.length; li++)
  {
   if (nodes[li].id.match(/^show-/))
   {
    nodes[li].className = (nodes[li].className=='last' ? 'plus-last' : 'plus');
   }
  }
}
}};


// Called on click of the entire tree, this manages visibility of sublevels.
CheckTree.prototype.click = function(e) { with (this)
{
e = e || window.event;
var elm = e.srcElement || e.target;

// Has a checkbox been clicked, but not processed by a lower level onclick event?
// If so, one of the 'root' checkboxes must have been clicked.
// We must therefore trigger a manual 'downwards route' for that tree to update it.
if (!e[evtProcessed] && elm.id && elm.id.match(/^check-(.*)/))
{
  var tree = document.getElementById('tree-' + RegExp.$1);
  if (tree) tree.setBoxStates(e, true, false);
}

while (elm)
{
  // Dont' do expand/collapses for clicks on checkboxes, or nested within menus.
  if (elm.tagName.match(/^(input|ul)/i)) break;
  // Show/hide the menu element that matches the source id="show-xxx" tag and quit.
  if (elm.id && elm.id.match(/^show-(.*)/))
  {
   var targ = document.getElementById('tree-' + RegExp.$1);
   if (targ.style)
   {
    var col = (targ.style.display == 'none');
    targ.style.display = col ? 'block' : 'none';
    // Swap the class of the <span> tag inside, maintaining "-last" state if applied.
    elm.className = elm.className.replace(col?'plus':'minus', col?'minus':'plus');
   }
   break;
  }
  // Otherwise, continue looping up the DOM tree, looking for a match.
  elm = elm.parentNode;
}
}};

function setBoxStates(e, routingDown, countOnly) { with (this)
{
// Opera <7 fix... don't perform any actions in those browsers.
if (!this.childNodes) return;

e = e || window.event;
var elm = e.srcElement || e.target;

// Initial check: if the parent checkbox for a tree level has been clicked, trigger a
// pre-emptive downwards route within that tree, and set returnValue to true so that we
// don't repeat it or mess with any of the original checkbox's siblings.
if (elm && elm.id && elm.id.match(/^check-(.*)/) && !routingDown && !e[treeObj.evtProcessed])
{
  var refTree = document.getElementById('tree-' + RegExp.$1);
  if (refTree)
  {
   refTree.setBoxStates(e, true, countOnly);
   e[treeObj.evtProcessed] = true;
  }
}

  // Some counter and reference variables.
var allChecked = true, boxCount = 0, subBoxes = null;
// Get the name of this branch and see if the source element has id="check-xxxx".
var thisLevel = this.id.match(/^tree-(.*)/)[1];
var parBox = document.getElementById('check-' + thisLevel);

// Loop through all children of all list elements inside this UL tag.
for (var li = 0; li < childNodes.length; li++)
{
  for (var tag = 0; tag < childNodes[li].childNodes.length; tag++)
  {
   var child = childNodes[li].childNodes[tag];
   if (!child) continue;
   if (child.tagName && child.type && child.tagName.match(/^input/i) &&
    child.type.match(/^checkbox/i))
   {
    // Set this box's state depending on its parent state, if we're routing downwards.
    if (routingDown && parBox && elm && elm.id && elm.id.match(/^check-/) && !countOnly)
     child.checked = parBox.checked;
    // Count the checked boxes directly under this level.
    allChecked &= child.checked;
    if (child.checked) boxCount++;
   }
   // And route this event to sublevels, to update their nodes, during a downwards route.
   if (child.tagName && child.tagName.match(/^ul/i) && (!e[treeObj.evtProcessed] || routingDown))
    child.setBoxStates(e, true, countOnly);
  }
}

// Once we've routed the event to all sublevels, set the 'returnValue' to true, so that
// upper levels don't re-trigger a downwards route. This is a bit of a hack, admittedly :).
if (!routingDown) e[treeObj.evtProcessed] = true;

// Next, set the parent parBox state depending if all checkboxes in this menu are checked.
// Of course, we don't set its state if it's the source of the event!
if (parBox && parBox != elm && !countOnly) parBox.checked = allChecked;

// If "countAllLevels" is set, overwrite the previous one-level-only count.
if (treeObj.countAllLevels)
{
  boxCount = 0;
  var subBoxes = this.getElementsByTagName('input');
  for (var i = 0; i < subBoxes.length; i++) if (subBoxes[i].checked) boxCount++;
}

// Either way, assign the counted value to the id="count-xxx" page element.
var countElm = document.getElementById('count-' + thisLevel);
if (countElm)
{
  while (countElm.firstChild) countElm.removeChild(countElm.firstChild);
  if (boxCount) countElm.appendChild(document.createTextNode(treeObj.checkFormat.replace('%n%',
   boxCount)));
}
}};


// Calls the init() function of any active trees on page load, and backup previous onloads.
var chtOldOL = window.onload;
window.onload = function()
{
if (chtOldOL) chtOldOL();
for (var i in CheckTree.list) CheckTree.list[i].init();
};
</script>
<script type="text/javascript">
<!--
var checkmenu = new CheckTree('checkmenu');
//-->
</script>
</head>

<body>

<form action="javascript:void(0)">
<ul id="tree-checkmenu" class="checktree">
<li id="show-explorer">
  <input id="check-explorer" type="checkbox" />
  Internet Explorer
  <span id="count-explorer" class="count"></span>
  <ul id="tree-explorer">
   <li id="show-iemac">
    <input id="check-iemac" type="checkbox" />
    Macintosh
    <span id="count-iemac" class="count"></span>
    <ul id="tree-iemac">
     <li><input type="checkbox" />v4.0</li>
     <li class="last"><input type="checkbox" />v5.0</li>
    </ul>
   </li>
   <li id="show-iewin" class="last">
    <input id="check-iewin" type="checkbox" />
    Windows
    <span id="count-iewin" class="count"></span>
    <ul id="tree-iewin">
     <li><input type="checkbox" />v4.0</li>
     <li><input type="checkbox" />v5.0</li>
     <li><input type="checkbox" />v5.5</li>
     <li class="last"><input type="checkbox" />v6.0</li>
    </ul>
   </li>
  </ul>
</li>
<li id="show-netscape">
  <input id="check-netscape" type="checkbox" />
  Netscape
  <span id="count-netscape" class="count"></span>
  <ul id="tree-netscape">
   <li><input type="checkbox" />v4.0x</li>
   <li><input type="checkbox" />v4.5-v4.7</li>
   <li><input type="checkbox" />v6.x</li>
   <li><input type="checkbox" />v7.x</li>
   <li id="show-mozilla" class="last">
    <input id="check-mozilla" type="checkbox" />
    Mozilla
    <span id="count-mozilla" class="count"></span>
    <ul id="tree-mozilla">
     <li><input type="checkbox" />pre-v1.0</li>
     <li><input type="checkbox" />v1.0</li>
     <li><input type="checkbox" />v1.1+</li>
     <li class="last"><input type="checkbox" />Firebird</li>
    </ul>
   </li>
  </ul>
</li>
<li id="show-opera">
  <input id="check-opera" type="checkbox" />
  Opera
  <span id="count-opera" class="count"></span>
  <ul id="tree-opera">
   <li><input type="checkbox" />v5.x</li>
   <li><input type="checkbox" />v6.x</li>
   <li class="last"><input type="checkbox" />v7.x</li>
  </ul>
</li>
<li id="show-khtml">
  <input id="check-khtml" type="checkbox" />
  KHTML
  <span id="count-khtml" class="count"></span>
  <ul id="tree-khtml">
   <li><input type="checkbox" />Safari</li>
   <li class="last"><input type="checkbox" />Konqueror</li>
  </ul>
</li>
<li class="last"><input type="checkbox" />Omniweb</li>
</ul>

</form>

 


</body>
</html> 

[출처] 웹디황용

"쇼핑몰·홈페이지·오픈마켓
블로그·페이스북·이메일 등의 각종 마케팅 글쓰기,
각종 광고, 영업, 판매, 제안서, 전단지
반응율 3배×10배 이상 높이는 마법의 8단계 공식"
자세히보기

Comments

번호 제목 글쓴이 날짜 조회
3165 TextArea 박스 내부에 밑줄이미지 삽입 99 단국강토 02.16 3869
3164 unix grep 명령어 사용법2번째 13 김영철 01.29 3863
3163 윈도우XP 풍선도움말 없애기 13 김영철 01.29 3857
3162 스타일이 적용된 selectbox 컨트롤 99 단국강토 12.30 3855
3161 [컴퓨터 키보드, 특수문자 정식 명칭들] M 최고의하루 12.18 3854
3160 MS outlook 2007 백업 프로그램입니다. 2 coruscate 09.14 3849
3159 알아두면 좋은 포토샵 단축키 총모음 M 최고의하루 12.19 3829
3158 history.back() 시 폼데이터 유지하기 13 김영철 01.15 3821
3157 원격데스크톱 연결 (원격제어) M 최고의하루 12.19 3815
3156 swf파일을 fla 파일로 변환하기 M 최고의하루 02.04 3813
3155 rsync 미러링을 통한 백업기법 13 김영철 01.29 3804
3154 [펌] 제11강 - ADO(Active Database Object) - Database Access Component Cobol vs C#-1 M 최고의하루 12.23 3804
3153 체크박스 배열을 edit 수정페이지로 불러오기 M 최고의하루 01.12 3804
3152 이것은 AI파일 미리보기입니다. 댓글2 M 최고의하루 01.15 3803
3151 미디어 컨트롤 소스 M 최고의하루 12.24 3790
열람중 체크박스 트리메뉴 99 단국강토 02.03 3789
3149 [MSSQL] 그룹별 상위 n명 가져오기 예제 13 김영철 01.23 3789
3148 ps 명령어 사용법 13 김영철 01.29 3780
3147 제약조건(1) M 최고의하루 12.20 3775
3146 자신의 아이큐 알아보기 댓글1 17 미니 04.27 3775
3145 웹프로그래밍 언어별 데이터베이스연결 (ASP편) 13 김영철 01.23 3770
3144 pcre 문법, preg | 13 김영철 01.13 3764
3143 PUTTY Telnet , SSH 접속 프로그램 99 단국강토 01.06 3759
3142 [Gmail] CSV 파일 Outlook에 적용하기 M 최고의하루 12.20 3757
3141 PDF 암호를 깨버리자 (APDFPRP) M 최고의하루 12.04 3744
3140 출력물로 판단하는 토너 카트리지 이상 증상 2 coruscate 09.14 3742
3139 contentEditable 속성 99 단국강토 02.09 3735
3138 DBA라면 이 정도는 알고 있어야 하지 않을까요 !!! 13 김영철 01.23 3727
3137 ServerXMLHTTP의 인코딩 문제 13 김영철 01.29 3724
3136 MSSQL에서 문자로 된 날짜 시간 차이값 얻기 13 김영철 01.24 3707
마케팅
특별 마케팅자료
다운로드 마케팅자료
창업,경영
기획,카피,상품전략
동기부여,성취