Jquery 从第页上所有表中的特定单元格获取值

Jquery 从第页上所有表中的特定单元格获取值,jquery,html,Jquery,Html,我想检索页面上所有此类div的div ID和相关价格数据(在div内的表中) 例如: <div class="post"> <div id="productdetail-0001"> <!-- ID --> <table class="detailProduk"> <tr> <th></th> <th class="priceData">290000</th> <

我想检索页面上所有此类div的div ID和相关价格数据(在div内的表中)

例如:

<div class="post">
<div id="productdetail-0001"> <!-- ID -->
<table class="detailProduk">
  <tr>
    <th></th>
    <th class="priceData">290000</th> <!-- price -->
  </tr>
  <tr>
    <td></td>
    <td class="stock">9</td>
  </tr>
</table>
</div>
</div>

<div class="post">
<div id="productdetail-0002"><!-- ID -->
<table class="detailProduk">
  <tr>
    <th></th>
    <th class="priceData">159000</th><!-- price -->
  </tr>
  <tr>
    <td></td>
    <td class="stock">9</td>
  </tr>
</table>
</div>
</div>
这是我的jquery:

$(document).each(function(){
   var harga = $( ".priceData" ).html();
   $( ".price" ).html( harga );
});

有更好的方法吗?

类似的方法可能会让您开始:

$('.priceData')。每个(函数(i,v){
设divid=$(v).closest('[id^=productdetail-]').attr('id');
设id=divid.split('-')[1];
设prx=$(v).text();
让currprx=$('.price').html();
如果(currprx==''){
$('.price').html(id+'--'+prx);
}否则{
$('.price').html(currprx+“\n”+id+'-'+prx);
}
//警报(id+'-'+prx);
});
表{边框折叠:折叠;}
th,td{border:1px solid#ccc;}
.price{最大宽度:100px;页边距顶部:20px;填充:5px;}
.price{背景:小麦;边框:1px纯橙;}

290000
9
159000
9
$(document).each(function(){
   var harga = $( ".priceData" ).html();
   $( ".price" ).html( harga );
});