gpt4 book ai didi

javascript - Jquery 通过 td 中的隐藏输入字段值选择 tr

转载 作者:太空宇宙 更新时间:2023-11-04 14:13:41 27 4
gpt4 key购买 nike

我是 jQuery 语言的初学者,我有一个问题。

我的网站上有这样一个表格:

<table id="filter-table" class="table table-striped">
<thead>
<tr>
<th>Code</th>
<th>Name</th>
<th>Typology</th>
<th>Select</th>
</tr>
</thead>
<tbody>
<tr>
<td>IYCE8</td>
<td>NAME</td>
<td>
<input class='typology' type='hidden' value='1'>TYPE1
<input class='typology' type='hidden' value='2'>TYPE2
<input class='typology' type='hidden' value='3'>TYPE3
</td>
<td>
<input type="checkbox">
</td>
</tr>
<tr>
<td>IYCE9</td>
<td>NAME2</td>
<td>
<input class='typology' type='hidden' value='1'>TYPE1
<input class='typology' type='hidden' value='2'>TYPE2
</td>
<td>
<input type="checkbox">
</td>
</tr>
</tbody>
</table>

如您所见,行有一个与类型相关的隐藏输入 (type1=>1)。

使用下拉选择器我选择一个值:

<select id="filter" name="filter">
<option value="">SELECT ONE</option>
<option value="1">TYPE1</option>
<option value="2">TYPE2</option>
<option value="3">TYPE3</option>
</select>

通过过滤器中的事件 OnChange,我想选择表中输入字段值 = 为下拉列表中所选行的所有行

我如何使用 Jquery 做到这一点?预先感谢所有帮助

最佳答案

您可以组合 attribute selector :has() selector :

Example Here

$('#filter').on('change', function () {
var $tr = $('#filter-table tr:has(.typology[value="' + this.value + '"])');
});

在上面的代码片段中,$tr是一个包含所有后代 tr 的 jQuery 对象包含类别为 .typology 的元素的元素以及与所选值相对应的值属性。

关于javascript - Jquery 通过 td 中的隐藏输入字段值选择 tr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34398277/

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