javascript - 如何遍历表并让 td 元素遵循条件
问题描述
我只是想让它在不符合要求tr
时隐藏起来td
,尝试使用 jQuery 和 JavaScript,不知道出了什么问题。
$(document).ready(function(){
$("td").each(function() {
var id = $(this).attr("price_search");
if (id > value4 && id < value5) {
$(this).hide;
}
else {
$(this).hide;
}
});
});
解决方案
你可以这样做。
希望这会帮助你。
$(document).ready(function() {
var value4 = 2;
var value5 = 4;
$("td").each(function() {
var id = $(this).attr("price_search");
if (id > value4 && id < value5) {
$(this).hide();
} else {
$(this).show();
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<td price_search="3">10</td>
<td price_search="2">20</td>
<td price_search="3">30</td>
</tr>
</table>
推荐阅读
- sql - 如何在 SQL 中将表连接到子查询结果?
- c# - 将 DataGridView 中的值添加到 SQL
- python - 如何使用 pygame.transform.scale 调整图像大小?
- python - GUI 单位转换米/英尺
- javascript - Django、html和js中的匹配卡片
- r - 如何在R中并行读取和写入csv文件
- node.js - 将 dockerized Nginx 上的 React App 连接到 Express 服务器
- reactjs - 不确定我的道具在反应原生打字稿中是什么类型
- c++ - 如何在 C++ 中的 switch 语句之后编写 if 语句?
- python - numpy如何避免gc引用计数对子进程的访问复制