我在从条件中的html获取特定值的循环中遇到问题。
如果div.column-ui.to-pay-column-ui.to-pay-column-lq
内有.column-ui.days-after-column-ui
,我必须从div.error-bg-ui.days-after-ui
跨度中获取值
在我的一些代码下面
<div class="invoices-table-ui table-lq" style="display: block;">
<div class="row-ui load-erp-invoice-details-lq parent-container-reload-lq" data-url="/profil-klienta,6?&deeper-lvl&erp-data&invoice-erp">
<div class="column-ui days-after-column-ui">
<!-- rivets: if o.DaysAfterExists -->
</div>
<div class="column-ui"></div>
<div class="column-ui to-pay-column-ui to-pay-column-lq">
<!-- rivets: if o.ToPayExists --><span>2 685,51 PLN</span>
<!-- rivets: if o.ToReturnExists -->
</div>
</div>
<div class="row-ui load-erp-invoice-details-lq parent-container-reload-lq" data-url="/profil-klienta,6?&deeper-lvl&erp-data&invoice-erp">
<div class="column-ui days-after-column-ui">
<!-- rivets: if o.DaysAfterExists -->
</div>
<div class="column-ui"></div>
<div class="column-ui to-pay-column-ui to-pay-column-lq">
<!-- rivets: if o.ToPayExists -->
<!-- rivets: if o.ToReturnExists -->
</div>
</div>
<div class="row-ui load-erp-invoice-details-lq parent-container-reload-lq" data-url="/profil-klienta,6?&deeper-lvl&erp-data&invoice-erp">
<div class="column-ui days-after-column-ui">
<!-- rivets: if o.DaysAfterExists -->
<div class="error-bg-ui days-after-ui">
1 dni po terminie
</div>
</div>
<div class="column-ui"></div>
<div class="column-ui to-pay-column-ui to-pay-column-lq">
<!-- rivets: if o.ToPayExists --><span>1 339,41 PLN</span>
<!-- rivets: if o.ToReturnExists -->
</div>
</div>
<script>
var companiesList = [];
$(document).ready(function(){
$('.invoices-table-ui.table-lq').each(function(index, element){
companiesList[index] = {};
var result = null;
( $(element).find(".column-ui.days-after-column-ui").has("div.error-bg-ui.days-after-ui").length ? result = $(element).find('.column-ui.to-pay-column-ui.to-pay-column-lq span').text().trim() : result = 0 )
companiesList[index] = result;
});
console.log(companiesList);
});
</script>
结果我得到的是
["2 685,51 PLN1 339,41 PLN"]
但我只需要
["1 339,41 PLN"]
谢谢您的任何建议。