0

すべての div で特定のテキスト「www.url.com」を検索しようとしています

www.url.com が見つかった場合、サブテーブルからテーブル ID を抽出します。

私のhtmlは次のようなものです:

<div class="box" id="results">
   <div class="box-header">
      <h1>www.url.com</h1>
   </div>
   <table cellpadding="0" cellspacing="0" border="0" class="display" id="24">
      <thead>
         <tr>
            <th>col</th>
         </tr>
         <tr id="161">
            <td class="kw" style="border-left: 1px solid white;border-right: 1px solid #F4F4F4;padding: 12px 14px;position: relative;text-align: left;">111111</td>

         </tr>
      </thead>
      <tbody></tbody>
   </table>

この場合、id="24" を見つけたいと思います。

これは私がこれまでに持っているものです:

var foundin = $('*:contains("www.url.com")');

IDを取得する方法がわかりません:)

4

3 に答える 3

3

使用する:

foundin.find('table').attr('id');

すべてのインスタンスを収集する場合は、次のようなものを使用します。

foundin.each(function(){
    $(this).find('table').attr('id'); // Gets the ID
    // Store it into something like an array
});
于 2012-12-21T13:20:08.893 に答える
0

これを試してみてください。すべてのテーブルが同じに見える場合、これは機能するはずです。

 $('*:contains("www.url.com")').find('table:first').attr('id');
于 2012-12-21T13:20:10.190 に答える
0
var tableId = $('*:contains("www.url.com")').closest('.box').find('table').attr('id');
于 2012-12-21T13:20:17.920 に答える