在我注释掉/或删除该alert()
行之前,我有一个运行良好的 Javascript 函数。它计算最多 30 个字段的总和(如果它们存在并且它们是否具有值)。
HTML:
<input type="text" onblur="Calculatenettobrutto(1);">
JavaScript:
function Calculatenettobrutto(n) {
var Feldnummer=n;
var nettowert,bruttowert;
var nettosumme, bruttosumme,neuenettosumme,neuebruttosumme;
var Wertfuer='Mehrwertsteuersatz'
//Mehrwertsteuer auslesen
var dataString = 'Name='+Wertfuer;
var thisObject = this;
this.wert=$.ajax({
type: "POST",
url: "ajax_get_Einstellungen.php",
data: dataString,
cache: false,
success: function(wert) {
nettowert = document.getElementById('Netto'+Feldnummer).value;
bruttowert = parseFloat(nettowert) * wert;
document.getElementById('Brutto'+Feldnummer).value=parseFloat(bruttowert);
return wert;
}
});
var nettosumme=0,bruttosumme=0, x=1;
while (x < 30) {
var Feldname='Netto'+x;
if ( document.getElementById('Netto'+x) ) {
//If field Netto+x exist then check if it has a value
var nettowert=document.getElementById('Netto'+x).value;
//if it has a value add values to nettosumme and bruttosumme
if (nettowert) {
nettosumme=parseFloat(nettosumme)+parseFloat(document.getElementById('Netto'+x).value);
//IF I COMMENT THIS OUT, I get a NAN in my Bruttosumme column
alert(nettosumme);
bruttosumme=parseFloat(bruttosumme)+parseFloat(document.getElementById('Brutto'+x).value);
}
}
x++;
}
document.getElementById('Nettosumme').value=parseFloat(nettosumme);
document.getElementById('Bruttosumme').value=parseFloat(bruttosumme);
}
即使alert()
线路被移除,我如何使它工作?