我正在創建一個定價界面,最終會爲用戶(體驗+集合)生成兩個不同的價格。爲了顯示總價格,我需要結合這些價格。體驗和收藏價格根據用戶的選擇而顯示,並且他們目前的工作效果很好。將兩個動態生成的HTML值與jQuery一起添加
但現在我想不出如何添加兩個html元素的html值。類total-cost
是應顯示此增加值的位置。我已經嘗試了很多東西,希望能夠自己搞清楚,但沒有運氣。
謝謝!與.cost1
類和可變.cost2
添加值,然後
每個格:
HTML(清理)
<div class="pricing-experience">
<div class="flex_column">
<span class="cost1">3000</span>
</div>
<div class="flex_column">
<span class="cost1">4000</span>
</div>
<div class="flex_column">
<span class="cost1">5000</span>
</div>
</div>
<div class="pricing-collection">
<div class="flex_column">
<span class="cost2">300</span>
</div>
<div class="flex_column">
<span class="cost2">450</span>
</div>
<div class="flex_column">
<span class="cost2">700</span>
</div>
</div>
<div class="experience-cost">
//cost1's value
</div>
<div class="collection-cost">
//cost2's value
</div>
<div class="total-cost">
//cost1 and cost2's added value
</div>
jQuery的
$('.pricing-experience, .pricing-collection').on('click', '.flex_column', function() {
var experienceCost = $(this).find('.cost1').html(),
collectionCost = $(this).find('.cost2').html();
$(this).addClass('elephant').siblings().removeClass('elephant');
// console.log(experienceCost);
// console.log(collectionCost);
$('.experience-cost').html(experienceCost);
$('.collection-cost').html(collectionCost);
$('.total-cost').html(experienceCost + collectionCost);
});
你可以顯示頁面的相關部分的HTML嗎? –
您可以請發佈什麼experienceCost返回? HTML? – Mircea
@LelioFaieta我已經更新了HTML。 – Delto