Tsu*_*oku 3 iteration each jquery
我有一个调用的数组prices,另一个调用orderT我要检查它是否是某个orderType然后我做某些事务,prices[i]如果它是一个不同的类型然后另一个事务(只有2种类型的订单).
到目前为止,我可以迭代价格(使用accounting.js插件):
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, ".", ","));
}
Run Code Online (Sandbox Code Playgroud)
价格部分运作良好,但我无法想象如何也去orderT检查.
编辑
orderT并且prices是相关的并且在表中,我不能发布所有表,因为它很大但它基本上是:
<td>order_type</td>
<td>$00.00</td>
Run Code Online (Sandbox Code Playgroud)
试试这个(假设.prices的数量与.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
}
});
Run Code Online (Sandbox Code Playgroud)
看起来.price和.orderType是相关的.如果您可以发布HTML,可以改进此代码以使用兄弟/其他选择器来访问.price和相应的.orderType
| 归档时间: |
|
| 查看次数: |
2358 次 |
| 最近记录: |