gpt4 book ai didi

javascript - 检索特定列/邮政编码

转载 作者:行者123 更新时间:2023-11-28 04:38:17 28 4
gpt4 key购买 nike

我试图仅检索此脚本中的邮政编码字段。

有没有办法只返回这个值?

<script>
function LookuptableWend(query) {
var tr = document.getElementsByTagName("tr"),y=0;
for (i = 0; i < tr.length; i++) {
if((y<25)&&(query)&&(tr[i].innerHTML.search(query)>-1)){
tr[i].className="found";y+=1;
}
else{tr[i].className="";
}
}
}
</script>
<小时/>
<table class="lookuptable" > 
<tbody>
<tr>
<td>0097040K</td>
<td>Hospital Name 1</td>
<td>2/70 Kent Street</td>
<td>Block 1 </td>
<td>DEAKIN</td>
<td>ACT</td>
<td>2600</td>
<td>02 6232 4793</td>
</tr>

<script>LookuptableWend(document.getElementById("search").value);</script>

最佳答案

您可以将querySelectorAllnth-child一起使用(下面的js中的注释)

function LookuptableWend(query) {
var td = document.querySelectorAll(".lookuptable td:nth-child(7)"); // get all postcode cells

for (i = 0; i < td.length; i++) {
if (td[i].innerHTML.search(query) != -1) { // search them for your query string
td[i].parentNode.className = "found"; // add a class to the row
} else {
td[i].parentNode.className = "";
}
}
}

LookuptableWend(2600);
.found {
background: green;
}
<table class="lookuptable">
<tbody>
<tr>
<td>0097040K</td>
<td>Hospital Name 1</td>
<td>2/70 Kent Street</td>
<td>Block 1 </td>
<td>DEAKIN</td>
<td>ACT</td>
<td>2600</td>
<td>02 6232 4793</td>
</tr>
<tr>
<td>0097040K</td>
<td>Hospital Name 1</td>
<td>2/70 Kent Street</td>
<td>Block 1 </td>
<td>DEAKIN</td>
<td>ACT</td>
<td>2601</td>
<td>02 6232 4793</td>
</tr>
<tr>
<td>0097040K</td>
<td>Hospital Name 1</td>
<td>2/70 Kent Street</td>
<td>Block 1 </td>
<td>DEAKIN</td>
<td>ACT</td>
<td>2600</td>
<td>02 6232 4793</td>
</tr>
</tbody>
</table>

关于javascript - 检索特定列/邮政编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43996026/

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