您好我想发送一封包含php代码的电子邮件。 我有以下脚本计算:
<script type="text/javascript">
window.onload = function () {
var total_of_order= <?php echo $order_total ?>;
var extra_costs= 38;
var total = Math.ceil(parseInt(total_of_order) - extra_costs);
$('calculateTotal').innerHTML = total;
}
</script>
<div id="calculateTotal"></div>
我如何将其编码为纯PHP? 样的?
<?php echo $extra_costs; $extra_costs= "38";?>
<?php echo $order_total ?>
<?php echo $total = Math.ceil(parseInt(order_total) - extra_costs);?>
你可以看到我是最糟糕的程序员,有人能帮帮我吗?
dfasf
答案 0 :(得分:1)
使用ceil
功能,不带Math.
前缀。此外,由于您在PHP中进行计算,因此可以直接在<div>
中输出结果,而无需任何JavaScript。
<div id="calculateTotal">
<?php
$order_total = ...; //Defined previously, not included in your question
$extra_costs = 38;
echo ceil($order_total - $extra_costs);
?>
</div>
答案 1 :(得分:0)
只需删除Math.
<?php echo $extra_costs; $extra_costs= "38";?>
<?php echo $order_total ?>
<?php echo ceil(order_total - extra_costs);?>
答案 2 :(得分:0)
<?php
$extra_costs= 38;
$total = ceil($order_total) - $extra_costs;
?>
<div id="calculateTotal"><?php echo $total ?></div>
答案 3 :(得分:0)
<?php
$extra_costs = 38;
$total = ceil($order_total - $extra_costs);
?>
<script type="text/javascript">
$('calculateTotal').innerHTML = '<?php=$total?>';
</script>