我以下代码返回每个与其关联的“price”类的文本。我只想返回每个陈述所在的具体项目的价格。
<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>
答案 0 :(得分:3)
jQuery('.part_number').each(function () {
parts.push(jQuery(this).text());
var aPrice= jQuery(this).siblings('.price').text();
})
答案 1 :(得分:-1)
好吧,我想你应该把HTML编码为。因为这三个项目都有“item”和“price”类关联。
<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>