【发布时间】:2021-09-09 05:17:18
【问题描述】:
如果 TD 的值在我指定的数组中,我会尝试在表上隐藏 TD。
<table border="1">
<tr class="tr-2">
<td class="weeknd">22</td>
<td class="weeknd">23</td>
<td class="weeknd">24</td>
<td class="weeknd">25</td>
<td class="weeknd">26</td>
</tr>
</table>
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
<script src="main.js"></script>
和脚本
const myarray = [22,23,24,25];
var weeknd = Array();
$(myarray).each(function(i) {
console.log(myarray[i])
})
$(".weeknd").each(function(index, i){
weeknd[index] = $(this).text();
if(weeknd[index] == myarray[i]){
$(this).hide()
}
})
这里是 Codepen:https://codepen.io/Xteripus/pen/yLMmZqw?editors=1111
【问题讨论】:
标签: javascript jquery arrays loops