1

我下面的代码返回与它关联的“价格”类的每个文本。我只想返回每个语句所在的特定项目的价格..

<div class="item">
    <p class="price">$388.00</p>
    <p class="part_number">VM2327T23A00T</p>
    <p class="real_price"></p>
</div>
<div class="item">
    <p class="price">$88.00</p>
    <p class="part_number">AA327T23A00T</p>
    <p class="real_price"></p>
</div>
<div class="item">
    <p class="price">$38.00</p>
    <p class="part_number">AA327T23A00T</p>
    <p class="real_price"></p>
</div>

<script>
jQuery('.part_number').each(function () {
    parts.push(jQuery(this).text());
    var aPrice= jQuery('.price').text();
});
</script>
4

2 回答 2

3
jQuery('.part_number').each(function () {
    parts.push(jQuery(this).text());
    var aPrice= jQuery(this).siblings('.price').text();
})
于 2012-06-27T18:23:37.190 回答
-1

好吧,我想您应该将 HTML 编码为。因为这三个项目都有与之关联的“项目”和“价格”类。

<div class="item" class="price">
   <p>$388.00</p>
     <p class="part_number">VM2327T23A00T</p>
     <p class="real_price"></p>
  <p>$88.00</p>
     <p class="part_number">AA327T23A00T</p>
     <p class="real_price"></p>
  <p>$38.00</p>
     <p class="part_number">AA327T23A00T</p>
     <p class="real_price"></p>
</div>
于 2012-06-27T18:26:46.033 回答