gpt4 book ai didi

javascript - 表存在但检查时返回0

转载 作者:行者123 更新时间:2023-12-02 21:10:54 25 4
gpt4 key购买 nike

我创建了一个具有特定 ID 的 HTML 表,但是当我尝试检查它是否存在时,它返回 0

<table border = "1px"cellpadding="0" cellspacing="1" width="100%" id="Evolución_Depósitos_a_Plazo_+_Restringidos" %> style="background: none repeat scroll 0% 0%;font-size:12px;">
<thead>
<td align="center" colspan="17">Evolución_Depósitos_a_Plazo_+_Restringidos</td>
<tr>
<td class="center"></td>
<td align="center" colspan="13">Evolución Tasa de Morosidad </td>
<td align="center" colspan="3">Variacion %</td>
</tr>
</thead>
<tbody></tbody>
</table>

我用这段代码来检查它是否存在: $('table#Evolución_Depósitos_a_Plazo_+_Restringidos').length

但是这会返回0。非常感谢帮助。谢谢。

最佳答案

该问题是由于选择器中的 + 字符导致的 special meaning 。您需要使用 \\ 对其进行转义。

另请注意,您的 HTML 无效。第一个 td 需要位于 tr 内。

console.log($('table#Evolución_Depósitos_a_Plazo_\\+_Restringidos').length);
table {
background: none repeat scroll 0% 0%;
font-size: 12px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table border="1px" cellpadding="0" cellspacing="1" width="100%" id="Evolución_Depósitos_a_Plazo_+_Restringidos">
<thead>
<tr>
<td align="center" colspan="17">Evolución_Depósitos_a_Plazo_+_Restringidos</td>
</tr>
<tr>
<td class="center"></td>
<td align="center" colspan="13">Evolución Tasa de Morosidad </td>
<td align="center" colspan="3">Variacion %</td>
</tr>
</thead>
<tbody>
</tbody>
</table>

关于javascript - 表存在但检查时返回0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61100912/

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