<script type="text/javascript">
$(document).ready(function() {
var sub_total = $("sub_total").text();
alert(sub_total);
var ship_total = $("ship_total").val()
alert(ship_total);
var new_total = sub_total + ship_total;
$('#new_total').html(new_total.toFixed(2));
});
</script>
경고를 사용하여 출력을 테스트했으며 범위 ID 안에 값을 가져 오지 않았습니다.ID로 두 요소의 값을 얻고 추가하는 방법
$<span id="sub_total"><?php echo $sub_total = number_format($this->cart->total(), 2); ?></span></td>
이것은 페이지에 올바르게 표시되지만 경고는 빈 상자입니다. 값을 숫자가 아닌 NaN
으로 계산합니다.
어떻게이 두 필드에 값을 추가합니까?
자바 스크립트에서 parseInt를 사용할 때 기수를 제공하는 것이 좋습니다. https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/parseInt – thescientist