gpt4 book ai didi

javascript - 在页面加载时隐藏 tbody,永久显示 thead 组,使用 jQuery 在下拉选择中显示 tbody

转载 作者:行者123 更新时间:2023-11-30 13:57:05 30 4
gpt4 key购买 nike

我试图首先在页面加载时仅显示 thead 和几行数据(永久显示分组在 thead 下的数据)。加载页面后,我希望选定的对象选择(不显示任何 tbody 组)并通过选择顶部下拉菜单中的选项(以显示选定的 tbody)为用户提供扩展数据的选项。 tbody 组将显示在永久行的底部。此代码不会在页面加载时隐藏 tbody,但会执行我希望它执行的其余操作。

参见我之前的问题 link

请帮忙。

这是代码示例。

//here is the custom JS we would like to add
$("#choice").change(function() {
$("table tbody").hide();
$("table tbody#" + $(this).val()).show('fast');
});
 <html>		
<body>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="choice">
<option selected value="">Choose...</option>
<option value="Year1">1 Year</option>
<option value="Years1-25">1 Year 3 Months</option>
<option value="Years1-5">1 Year 6 Months</option>
<option value="Years2">2 Years</option>
</select>

<table id="table">
<thead>
<tr>
<th>hello</th>
<th>hello</th>
<th>hello</th>
<th>hello</th>
<th>hello</th>
<th>hello</th>
<th>hello</th>
</tr>
<tr>
<td>Permanentrow1</td>
<td>Permanentrow1</td>
<td>Permanentrow1</td>
<td>Permanentrow1</td>
<td>Permanentrow1</td>
<td>Permanentrow1</td>
<td>Permanentrow1</td>
</tr>
<tr>
<td>Permanentrow2</td>
<td>Permanentrow2</td>
<td>Permanentrow2</td>
<td>Permanentrow2</td>
<td>Permanentrow2</td>
<td>Permanentrow2</td>
<td>Permanentrow2</td>
</tr>
</thead>

<tbody id="Year1">
<tr>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
</tr>
<tr>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
</tr>
</tbody>

<tbody id="Years1-25">
<tr>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
</tr>
<tr>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
</tr>
</tbody>

<tbody id="Years1-5">
<tr>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
</tr>
<tr>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
</tr>
</tbody>

<tbody id="Years2">
<tr>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
</tr>
<tr>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
</tr>
</tbody>
</table>


</body>
</html>

最佳答案

您好,我做了一些研究并提出了解决方案。

见下文:

//here is the custom JS we would like to add
$(document).ready(function(){
$('tbody').hide();

$("#choice").change(function() {
$("table>tbody").hide();
$("table>tbody#" + $(this).val()).show('fast');
});
});
     <html>		
<body>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="choice">
<option selected value="">Choose...</option>
<option value="Year1">1 Year</option>
<option value="Years1-25">1 Year 3 Months</option>
<option value="Years1-5">1 Year 6 Months</option>
<option value="Years2">2 Years</option>
</select>

<table id="table">
<thead>
<tr>
<th>hello</th>
<th>hello</th>
<th>hello</th>
<th>hello</th>
<th>hello</th>
<th>hello</th>
<th>hello</th>
</tr>
<tr>
<td>Permanentrow1</td>
<td>Permanentrow1</td>
<td>Permanentrow1</td>
<td>Permanentrow1</td>
<td>Permanentrow1</td>
<td>Permanentrow1</td>
<td>Permanentrow1</td>
</tr>
<tr>
<td>Permanentrow2</td>
<td>Permanentrow2</td>
<td>Permanentrow2</td>
<td>Permanentrow2</td>
<td>Permanentrow2</td>
<td>Permanentrow2</td>
<td>Permanentrow2</td>
</tr>
</thead>

<tbody id="Year1">
<tr>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
</tr>
<tr>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
<td>Year1</td>
</tr>
</tbody>

<tbody id="Years1-25">
<tr>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
</tr>
<tr>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
<td>Years1-25</td>
</tr>
</tbody>

<tbody id="Years1-5">
<tr>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
</tr>
<tr>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
<td>Years1-5</td>
</tr>
</tbody>

<tbody id="Years2">
<tr>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
</tr>
<tr>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
</tr>
<tr>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
</tr>
<tr>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
</tr>
<tr>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
<td>Years2</td>
</tr>


</tbody>
</table>


</body>
</html>

关于javascript - 在页面加载时隐藏 tbody,永久显示 thead 组,使用 jQuery 在下拉选择中显示 tbody,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57053052/

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