Javsscript 代碼:
function sumPrice() {
var sum_all = 0;
var num_sum = 0;
for (var i = 0; i < num; i++) {
if(document.getElementById("deposit"+i)!=null) {
var sum = Math.round(document.getElementById("pprice" + i).value *
document.getElementById("pnum" + i).value * document.getElementById("deposit" + i).value );
document.getElementById("psum" + i).innerHTML = sum;
num_sum += Math.round(document.getElementById("pnum" + i).value);
sum_all += sum;
}
}
document.getElementById("pamountsum").innerHTML = sum_all;
document.getElementById("pnumsum").innerHTML = num_sum;
document.getElementById("money").value = sum_all;
}
HTML 代碼:
<input type="hidden" name="money" value="" />
js報錯說document.getElementById("money").value = sum_all;值為null或未定義
<input type="hidden" name="money" value="" />
裡面沒有設置 id,修改下:
<input type="hidden" name="money" id="money" value="" />