vir*_*s90 0 html javascript jquery multiplication
我想将2以下字段的内容相乘,并在另一个div中输出总数(24*£20.00):
<label class="tm-show-picker-value" for="tmcp_range_4">24</label>
<span class="price amount final">£20.00</span>
Run Code Online (Sandbox Code Playgroud)
我使用jQuery尝试了下面的方法,但我对此并不是很熟悉 - https://jsfiddle.net/e8shpr0e/
$('.total').html(
parseFloat($('.tm-show-picker-value').text()) * parseFloat($('.price amount final').text())
)Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<label class="tm-show-picker-value" for="tmcp_range_4">24</label>
<span class="price amount final">£20.00</span>
<div class="total"></div>Run Code Online (Sandbox Code Playgroud)
任何帮助都会很棒.
您的代码中存在2个问题.
使用以下代码.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<label class="tm-show-picker-value" for="tmcp_range_4">24</label>
<span class="price_amount_final">£20.00</span>
<div class="total"></div>
var quantity = parseFloat($('.tm-show-picker-value').text());
var cost = parseFloat($('.price_amount_final').text().replace("£", ""));
$('.total').text("£" + quantity * cost );
Run Code Online (Sandbox Code Playgroud)