我正在尝试学习jQuery ...语法使我感到困惑。也许我做错了与语法有关。
此行提醒值36:
$(alert(('.htCore tbody tr th.ht_nestingParent').length));
[当我在浏览器中进行检查并按CTRL + F时,我只找到6;不是36。所以,我试图遍历它找到的每一个,并将其转储为控制台或警告html值;这样,我可以尝试找出为什么它说的是36而不是6。
这是我制作的循环...但是运行时它什么也没做。
$(document).ready(function() {
$('.htCore tbody tr th.ht_nestingParent').each(function (i) {
$val = $(this).html;
alert($val);
});
});
这是我的HTML
<tbody>
<tr>
<th class="ht_nestingLevels ht_nestingParent"><div class="relative"><span class="rowHeader">1</span>
<div class="ht_nestingButton ht_nestingCollapse"></div>
</div></th>
<td class="">7-ELEVEN</td>
<td class="">22971161</td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
</tr>
<tr>
<th class="ht_nestingLevels ht__highlight"><div class="relative"><span class="ht_nestingLevel_empty"></span><span class="rowHeader">2</span></div></th>
<td class="current highlight"></td>
<td class=""></td>
<td class="">A</td>
<td class="">SOUTH MOD 67 ID FACE||7-11 OKLAHOMA COLORS||95-5/8 X 96-3/4||DWG: SO1067RF.OK (102138)||</td>
<td class="">4</td>
<td class="">2020-02-20</td>
<td class="">2020-01-24</td>
</tr>
<tr>
<th class="ht_nestingLevels ht_nestingParent"><div class="relative"><span class="rowHeader">3</span>
<div class="ht_nestingButton ht_nestingCollapse"></div>
</div></th>
<td class="">7-ELEVEN</td>
<td class="">22983321</td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
<td class=""></td>
</tr>
</tbody>
我的目标是查找带有.ht_nestingParent类的标签,然后在.ht_nestingParent上方添加空白表行,然后在其最后一个子行下方添加空白行;下面的行缺少.ht_nestingParent类。
此行写得不好
$(alert(('.htCore tbody tr th.ht_nestingParent').length));
您收到的36是此字符串.htCore tbody tr th.ht_nestingParent
中的字符数,因为您只是在提醒字符串的长度。
这应该给您正确的号码
alert($('.htCore tbody tr th.ht_nestingParent').length);