我有一个string
我正在使用string.split(' ');
的拆分,以便将字符串转换为数组。
假设我有这两个表,table1
并且table2
.
<table border="1" id="table1">
<tr>
<th colspan="2">Image One</th>
</tr>
<tr>
<td style="width:40%;"><img src="airplane.jpg" alt="Image 1"></td>
<td>
<dl>
<dt>airplane</dt>
<dt>flight</dt>
<dt>travel</dt>
<dt>military</dt>
<dt>word war</dt>
<dt>GI</dt>
</dl>
</td>
</tr>
</table>
<table border="1" id="table2">
<tr>
<th colspan="2">Image Two</th>
</tr>
<tr>
<td style="width:40%;"><img src="apple.jpg" alt="Image 1"></td>
<td>
<dl id="tags">
<dt>red</dt>
<dt>apple</dt>
<dt>round</dt>
<dt>fruit</dt>
<dt>healthy</dt>
<dt>doctor</dt>
</dl>
</td>
</tr>
</table>
现在出于测试目的,我有一个 id 的tags
on table2
's dl
。
我正在使用一个函数将DL
(#tags) 转换为一个数组
function getArray(id) {
var node, list, arrValue;
array = [];
for (node = document.getElementById(id).firstChild;
node;
node = node.nextSibling) {
if (node.nodeType == 1 && node.tagName == 'DT') {
array.push(node.innerHTML);
}
}
console.log(array)
}
为了对照我的原件检查它string
,看看是否有任何值匹配。但是,我将要检查多个DT
's string
。将所有表添加到 3d 数组中然后检查 3d 数组中的值是否正确string
?还是有更好的方法?
更新
问题是:
我最终将有一张充满图像和标签的表格。本质上,我希望能够根据我的字符串(将被分成一个数组)搜索这些标签,然后返回字符串中标签最多的图像。我试图找出最好的方法来做到这一点。谢谢