중복된 개체 id 확인 > script

본문 바로가기
사이트 내 전체검색

script

중복된 개체 id 확인

페이지 정보

작성자 서방님 댓글 0건 조회 202회 작성일 07-08-22 08:37

본문

<html>
<head>
<script>

idAllList = new Array();
// 태그목록 배열을 인수로 받아서 아이디를 추출하여
// 아이디목록을 배열로 리턴한다
function getAllIdList(tagList) {
 idx = 0;
 for(i=0; i<tagList.length; i++) {
  objList = document.body.all.tags(tagList[i]);
 for(j=0; j < objList.length; j++) {
  if( objList[j].id != null )
   idAllList[idx++] = objList[j].id;
 }
 }
 return idAllList;
}

// 아이디를 인수로 받아 아이디가 중복된 아이디인지 검증
function doubleIdName(idName) {
 count=0;
 len = idAllList.length;
 for(i=0; i<len; i++) {
  if(idAllList[i] == idName)
   count++;
  if(count==2) return 1;  // 중복이다
 }
 return false;  // 중복이 아니다
}
</script>
</head>

<body>

<div id="t1">fdads</div>
<div id="t2">fdads</div>
<div id="t3">fdads</div><span id="t4">fadf</span>
<table id="t2">
 <tr>
  <td>.</td>
 </tr>
</table>
<button onclick="chkTest()">아이디중복검사예제실행</button>

<script>
function chkTest() {
  allList = new Array();
  // 아이디를 검증할 태그 리스크를 배열로 선언한다
  tagList = new Array("div", "span","table","layer");
  allList = getAllIdList(tagList);

  document.write("<hr>id 목록은 아래와 같습니다<br>");
  for(i=0; i<allList.length; i++) {
   document.write(allList[i]+"<br>");
  }

 // 주어진 아이디가 중복인지 검증
 if(doubleIdName('t1')) document.write("t1 은 중복아이디입니다.<br>");
 else document.write("t1 은 중복아이디가 아닙니다.<br>");

 if(doubleIdName('t2')) document.write("t2 는 중복아이디입니다.<br>");
 else document.write("t2 는 중복아이디가 아닙니다.<br>");
}
</script>

</body>
</html>

댓글목록

등록된 댓글이 없습니다.

Total 846건 26 페이지
게시물 검색

회원로그인

접속자집계

오늘
29
어제
302
최대
1,347
전체
155,090
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.