Zugriff habe ich einige Codes wie so:jQuery .each() Funktion andere Wähler über Indizes
var theQuantities = $('#' + theWindowID + '_form INPUT[name=f\\[invoices_items\\]\\[quantity\\]\\[\\]]');
var theValues = $('#' + theWindowID + '_form INPUT[name=f\\[invoices_items\\]\\[value\\]\\[\\]]');
var theDiscounts = $('#' + theWindowID + '_form INPUT[name=f\\[invoices_items\\]\\[discount\\]\\[\\]]');
var theInvoiceTotalCell = $('#' + theWindowID + '_TDinvoice_total');
var invoiceTotal = 0;
for (var i = 0; i < theQuantities.length; i++) {
if ($.isNumeric(theQuantities[i].val()) && $.isNumeric(theValues[i].val()) && $.isNumeric(theDiscounts[i].val())) {
$('#' + theWindowID + '_' + theRowIDs[i].val() + '_TDinvoice_items_subtotal').html('$ ' + parseFloat((theQuantities[i].val() * theValues[i].val()) - theDiscounts[i].val()).toFixed(2));
var theSubTotal = parseFloat((theQuantities[i].val() * theValues[i].val()) - theDiscounts[i].val()).toFixed(2);
invoiceTotal += parseFloat(theSubTotal)
}
}
aber es nicht funktioniert und ich rufe Sie die folgenden Fehler TypeError: theQuantities[i].val is not a function
Ich glaube, ich muß Verwenden Sie .Each jedoch muss ich auch theValues
und theDisounts
referenzieren.
Wie kann man auf andere Selektoren mit demselben Index innerhalb der .each() - Funktion zugreifen?
So etwas wie dies, dass auch die theValues
und theDisounts
auch zugreifen können:
theQuantities.each(function(index, item) {
if ($.isNumeric(this.val()) && $.isNumeric(theValues[index].val()) && $.isNumeric(theDiscounts[index].val())) {
$('#'+theWindowID+'_'+theRowIDs[index].val()+'_TDinvoice_items_subtotal').html('$ ' + parseFloat((this.val() * theValues[i].val()) - theDiscounts[i].val()).toFixed(2));
var theSubTotal = parseFloat((this.val() * theValues[i].val()) - theDiscounts[i].val()).toFixed(2);
invoiceTotal += parseFloat(theSubTotal);
}
});
Was bekommen Sie, wenn Sie 'theQuantities' anmelden? – LinkinTED
'theValues [index]' ist das gleiche wie das Aufrufen von ['.get()'] (https://api.jquery.com/get/) auf 'theValues' -> es gibt den DOM-Knoten zurück. Verwenden Sie stattdessen ['.eq()'] (https://api.jquery.com/eq/) – Andreas