我想使用相關元素的文本(mcost_el=mcount_el*mprice_el
)運行計算並將結果寫入另一個元素(「mcost_el」)的文本中。使用jQuery中的元素內容進行計算
<tr>
<td class="mcount_el">2</td>
<td class="mprice_el">544,33</td>
<td class="mcost_el">0</td>
</tr>
<tr>
<td class="mcount_el">3,9</td>
<td class="mprice_el">460,00</td>
<td class="mcost_el">0</td>
</tr>
我寫這篇文章的代碼:
var count=0;
var price=0;
$('.mcost_el').each(function(){
count=parseInt($('.mcount_el').each.text().replace(",","."));
price=parseInt($('.mprice_el').each.text().replace(",","."));
$('.mcost_el').html(parseFloat(count)*parseFloat(price));
});
,但它不工作。
我編輯的問題,以反映我的理解你的要求,請回滾如果此編輯爲不正確。 – StuperUser