我写了以下代码:
function chkDiscount()
{
$pckg_value = 0;
plan = document.getElementById("PFirst").value;
if (plan === "Year") {
document.getElementById("discount").innerHTML = "15% discount";
<?php
$pckg_value = ($pckg_cost - 15) * 12;
?>
}
if (plan === "HalfYear") {
document.getElementById("discount").innerHTML = "10% discount";
<?php
$pckg_value = ($pckg_cost - 10) * 6;
?>
}
if (plan === "Quarter") {
document.getElementById("discount").innerHTML = "5% discount";
<?php
$pckg_value = ($pckg_cost - 5) * 3;
?>
}
}
我在其余代码中使用 $pckg_value。但它在每个选择中显示相同的值。即总是显示在最后一个 if 块中计算的值。请帮助我在每个选择上显示正确的计算。请帮助。