How can I iterate over 2 arrays at the same time using $.each()
I have an array called prices
and another called orderT
I want to check if it's of a certain orderType then I do certain transactions with prices[i]
if it's a different type then another transaction (only 2 types of orders).
So far I can iterate through prices (using accounting.js plugin):
function processTotal(){
var prices = $('.prices');
var orderT = $('.orderType');
var total = 0;
$.each(prices, function(i, e){
total += accounting.unformat(prices[i].textContent);
});
total = parseFloat(total);
$('#sum').text(accounting.formatMoney(total, "€", 2, ".", ","));
}
the prices part works very well, but I can't figure how to also go over the orderT
to check.
EDIT
orderT
and prices
are related and are in a table, I can't post all the table as it is quite big but it's basically:
<td>order_type</td>
<td>$00.00</td&开发者_JS百科gt;
Try this(assuming the number of .prices is same as .orderType):
$.each(prices, function(i, e){
var orderType = orderT [i];
if(orderType.textContent == "2"){
//Do Something
} else {
//total += accounting.unformat(prices[i].textContent);
//Do Something
}
});
Looks like the .price and .orderType are related. If you can post the HTML, this code can be improved to use the siblings/other selectors to access .price and corresponding .orderType
精彩评论