gpt4 book ai didi

javascript - 遍历 HTML 表并过滤某些列值

转载 作者:行者123 更新时间:2023-12-03 02:42:19 25 4
gpt4 key购买 nike

我使用下面的JS来迭代一个html表,并从表中的许多行中提取第1列和第2列的值,我得到的值包含一堆我不需要的信息,即

我得到第 1 列的以下内容:

<div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset">
<input name="asset_cost_19" type="text" value="$5,000.00">
</div>

我只想获得美元值(value):

$5,000.00

对于第 2 列,我得到以下信息:

<fieldset data-role="controlgroup" data-type="horizontal" class="ui-controlgroup ui-controlgroup-horizontal ui-corner-all">
<div class="ui-controlgroup-controls ">
<div class="ui-checkbox ui-mini">
<label for="asset_allocation_capex_19" class="ui-btn ui-corner-all ui-btn-inherit ui-checkbox-off ui-first-child">
Capex
</label>
<input type="checkbox" name="asset_allocation_capex_19" id="asset_allocation_capex_19" data-mini="true">
</div>
<div class="ui-checkbox ui-mini">
<label for="asset_allocation_opex_19" class="ui-btn ui-corner-all ui-btn-inherit ui-checkbox-on ui-btn-active ui-last-child">
Opex
</label>
<input type="checkbox" name="asset_allocation_opex_19" id="asset_allocation_opex_19" data-mini="true" checked="">
</div>
</div>
</fieldset>

我想知道在哪里检查asset_allocation_opex_asset_allocation_capex_,即

checked=""

以第 11 行为例

<input type="checkbox" name="asset_allocation_opex_11" id="asset_allocation_opex_11" data-mini="true" checked="">    
<input type="checkbox" name="asset_allocation_capex_11" id="asset_allocation_capex_11" data-mini="true">

代码:

$("#myTable_asset").children("tbody").children("tr").each(function (i) {
var $this = $(this);
var my_td = $this.children("td");
var second_col = my_td.eq(1);
var third_col = my_td.eq(2);
console.log("Second Column Value (row " + i + "): " + second_col.html());
console.log("Third Column Value (row " + i + "): " + third_col.html());
});

最佳答案

替换

console.log("Second Column Value (row " + i + "): " + second_col.html());

console.log("Second Column Value (row " + i + "): " + second_col.find("input[type=text]").val());

关于javascript - 遍历 HTML 表并过滤某些列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48274354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com