2010-08-13 4 views
1

과 다른 테이블에 중첩 테이블에서 ID 값을 얻으려면 어떻게해야 다음과 같은 HTML (코드 조각) : jQuery를

    <td class="ms-vb-title" height="100%"> 
         <table class="ms-unselectedtitle" onmouseover="OnItem(this)" 
         ctxname="ctx1" id="5" url= 
         "/Business%20Divisions/5_.000" dref= 
         "/Business Divisions" perm="0x7fffffffffffffff" 
         type="" ext="" icon="icgen.gif||" otype="0" couid="" hcd="" 
         csrc="" ms="0" ctype="Item" cid= 
         "0x010072628A3517FD5F4A8D399BADE8A6D104" uis="512" surl=""> 
         <tbody> 
          <tr> 
          <td class="ms-vb" width="100%"><a onfocus="OnLink(this)" 
          href= 
          "/Business%20Divisions/DispForm.aspx?ID=5" 
          onclick="GoToLink(this);return false;" target= 
          "_self">Commercial</a></td> 

          </tr> 
         </tbody> 
         </table> 
        </td> 
        </tr> 

가 지금은 클래스 ㆍ MS-unselectedtitle와 테이블의 ID를 얻으려면 어레이에 저장하십시오. 그래서 클래스 ㆍ MS-unselectedtitle와 함께 테이블의 모든 ID를 얻을 수있는 방법이 있는지 궁금하지만

var businessUnitID = new Array(); 
$('.ms-unselectedtitle').each(function(){ 
businessUnitID.push($(this).attr('id')); 

클래스 ㆍ MS-unselectedtitle가 HTML의 다른 많은 곳에서 사용되어진다 : 나는이 작업을 수행 그 .ms-vb-title 클래스의 부모 td가 있습니까? 또는 클래스 .ms-vb-title, table (클래스 ..ms-unselectedtitle) 하위 클래스의 모든 ID를 가져 오겠습니까?

미리 감사드립니다.

당신은 (클래스 .ms-vb-title와 학부모 TD) 클래스 .ms-unselectedtitle와 테이블의 모든 ID를 얻기 위해,이 시도 할 수

답변

1

:

// filter out all tables with immediate parent td.ms-vb-title 
// returns a collection 
var ids = $('.ms-unselectedtitle').filter(function() { 
    return $(this).parent('td').hasClass('.ms-vb-title'); 

// from resulting collection, grab all IDs 
}).map(function() { 
    return this.id; 

// convert to array 
}).get(); 

여기를보십시오 : 나는 이것을 척 어떻게, http://jsfiddle.net/Nt7zv/

+0

확인 배열? – Peter

+0

businessUnitID.push (ids); 나는 – Peter

+0

이 (가) 유감이지만, 약간의 설명이 추가되었습니다. 위의 예제에서'ids'는 일치하는 요소의 모든 ID를 가진 배열입니다. – karim79