我想收集冠状外的数字——正确的方法是什么?
<body>
<div id="HQ"></div>
<table class="table" border="2">
<tr>
<td>AAAA</td>
<td>
<span class="A"></span>
"6"
<span class="B"></span>
"4"
<span class="C"></span>
"5"
<span class="D"></span>
"5"
</td>
</tr>
</table>
<table class="table" border="2">
<tr>
<td>AAAA</td>
<td>
<span class="A"></span>
"9"
<span class="B"></span>
"4"
<span class="C"></span>
"2"
<span class="D"></span>
"2"
</td>
</tr>
</table>
<table class="table" border="2">
<tr>
<td>AAAA</td>
<td>
<span class="A"></span>
"7"
<span class="B"></span>
"4"
<span class="C"></span>
"5"
<span class="D"></span>
"1"
</td>
</tr>
</table>
</body>
脚本:
<script>
$(function(){
var texts = $('td *').map(function() {
if (this.nextSibling.nodeType == 3)
return this.nextSibling.nodeValue;
});
var a = texts[0];
var b = texts[1];
var c = texts[2];
var d = texts[3];
A = Number(a)
B = Number(b)
C = Number(c)
D = Number(d)
$("#HQ").html(A);
});
</script>
我想收集表格内的所有数字。
我只是想要class="A"
。
<span class="A"></span>
"6"
6 + 7 + 9 = 22
尝试了上面的代码,但没有成功。