我有一个表单字段 x_amount,它根据从下拉列表中的选择填充了一个静态数字,出于某种原因,它以 x_ship_to_address 的形式出现。如果选择 1 或 2,x_amount 将填充 25 或 45。如果选择 3 或 4,用户在 payment_mount 中输入一个值,然后 x_amount 变为 payment_amount x 1.03。我想要,如果用户选择 1 或 2,则 payment_amount 和 x_amount 都填充 25 或 45。这是正在使用静态数字填充 x_amount 的 JS:
function SI_money(amount) {
// makes sure that there is a 0 in the ones column when appropriate
// and rounds for to account for poor Netscape behaviors
amount=(Math.round(amount*100))/100;
return (amount==Math.floor(amount))?amount+'.00':((amount*10==Math.floor(amount*10))?amount+'0':amount);
}
function calcTotal(){
var total = document.getElementById('x_amount');
var amount = document.getElementById('payment_amount');
var payment = document.getElementById('x_ship_to_address');
if( payment.selectedIndex == 0)
total.value = 'select Type of Payment from dropdown';
else if( payment.selectedIndex == 3 || payment.selectedIndex == 4 )
total.value = SI_money(parseFloat(amount.value * 1.03));
else if( payment.selectedIndex == 1 )
total.value && amount.value = SI_money(25.00);
else if( payment.selectedIndex == 2 )
total.value = SI_money(45.00);
}
我想我希望 calcTotal 的最后两个 if 类似于:
else if( payment.selectedIndex == 1 )
total.value && amount.value = SI_money(25.00);
else if( payment.selectedIndex == 2 )
total.value && amount.value = SI_money(45.00);
但是添加 && 会抛出错误。我想我只是遗漏了一些关于语法的东西——我怎么说这两个字段都填充了正确的静态数字?