2016-12-23 3 views
0

tbodyに入れ子になった値の値を取得したいとします。ここに、私が意味するものを示す例があります。jQueryどのようにtbodyのネストされた値をキャッチする?

この例では、hrefに格納されているすべての値を取得したいとします。

<table id="toc" class="plainlinks" style="text-align: center" align="center"> 
    <tbody> 
    <tr> 
     <td><b>Index</b></td> 
    </tr> 
    <tr> 
     <td> 
     <p> 
      <a class="external text" href="//nl.wiktionary.org/w/index.php?title=Categorie:Zelfstandig-naamwoordsvorm_in_het_Nederlands&amp;from=A">A</a> 
      - <a class="external text" href="//nl.wiktionary.org/w/index.php?title=Categorie:Zelfstandig-naamwoordsvorm_in_het_Nederlands&amp;from=Ab">Ab</a> 
      - <a class="external text" href="//nl.wiktionary.org/w/index.php?title=Categorie:Zelfstandig-naamwoordsvorm_in_het_Nederlands&amp;from=Ad">Ad</a> 
      - <a class="external text" href="//nl.wiktionary.org/w/index.php?title=Categorie:Zelfstandig-naamwoordsvorm_in_het_Nederlands&amp;from=Ag">Ag</a> 
      - <a class="external text" href="//nl.wiktionary.org/w/index.php?title=Categorie:Zelfstandig-naamwoordsvorm_in_het_Nederlands&amp;from=Al">Al</a> 
      - <a class="external text" href="//nl.wiktionary.org/w/index.php?title=Categorie:Zelfstandig-naamwoordsvorm_in_het_Nederlands&amp;from=Ap">Ap</a> 
      - <a class="external text" href="//nl.wiktionary.org/w/index.php?title=Categorie:Zelfstandig--naamwoordsvorm_in_het_Nederlands&amp;from=Ap1">Ap1</a> 
     </p> 
     </td> 
    </tr> 
    </tbody> 
</table> 

私は値をキャッチし、次のステートメントを試してみました:

$('table tr').each(function (index, value) { 
    $('td' ,this).each(function (index, value) { 
    $('p', this).each(function (index, value) { 
     $('a',this).each(function (index, value) { 
     console.info($(this).html()) 
     }); 
    }); 
    }); 
}); 
+0

だからいいえあなたがしたいことをやっている? –

答えて

2
$('table tbody a').each(function(i,el){ 
console.info($(el).attr('href')); 
}) 

は "" "TBODY" で

0

javascriptのアプローチ

Array.prototype.map.call(document.querySelectorAll('table td a'),function(rm){console.log(rm.href)}) 
をすべてを取るだろう
関連する問題