gpt4 book ai didi

css - 需要 html 帮助在一个唯一的选定 ID 下显示多行

转载 作者:行者123 更新时间:2023-11-28 02:05:58 25 4
gpt4 key购买 nike

我有这张表,我试图根据单个 ID 显示两行,但根据下拉选择只显示 col-1 和 col-2。 col-3 & col-4 永远不会消失。我知道在一个文档中多次使用唯一 ID 不是最佳做法,这就是为什么我将所有“td”都放在一个具有唯一 ID 的“tr”下,我正在努力弄清楚为什么只有“inv”类适用于第一行或前两个“td”

有什么线索吗?

    <style>
.inv {
display: none;
}
</style>

<table class="blueTable">
<select id="target">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
</select>
<tbody>

<tr id="CA" class="inv">
<td>
col-1
</td>
<td>
Col-2
</td>
<td>
col-3
</td>
<td>
col-4
</td>
</tr>
</tbody>
</table>
<script>
document
.getElementById('target')
.addEventListener('change', function () {
'use strict';
var vis = document.querySelector('.vis'),
target = document.getElementById(this.value); // get the option id selected
if (vis !== null) { // reset the vis tag state
vis.className = 'inv';
}
if (target !== null ) {// if target not null then set the target link to visable state
target.className = 'vis';
}
});
</script>

Here is the css code

 table.blueTable {


font-family: Georgia, serif;
border: 1px solid #1C6EA4;
background-color: #EEEEEE;
width: 100%;
text-align: left;
border-collapse: collapse;
}
table.blueTable td, table.blueTable th {
border: 1px solid #CFCFCF;
padding: 3px 2px;
}
table.blueTable tbody td {
font-size: 12px;
}
table.blueTable tr:nth-child(even) {
background: #D0E4F5;
}
table.blueTable thead {
background: #1C6EA4;
background: -moz-linear-gradient(top, #5592bb 0%, #327cad 66%, #1C6EA4 100%);
background: -webkit-linear-gradient(top, #5592bb 0%, #327cad 66%, #1C6EA4 100%);
background: linear-gradient(to bottom, #5592bb 0%, #327cad 66%, #1C6EA4 100%);
border-bottom: 2px solid #9C9C9C;
}
table.blueTable thead th {
font-size: 15px;
font-weight: bold;
color: #FFFFFF;
border-left: 2px solid #D0E4F5;
}
table.blueTable thead th:first-child {
border-left: none;
}

table.blueTable tfoot td {
font-size: 14px;
}
table.blueTable tfoot .links {
text-align: right;
}
table.blueTable tfoot .links a{
display: inline-block;
background: #1C6EA4;
color: #FFFFFF;
padding: 2px 8px;
border-radius: 5px;
}

最佳答案

W3Schools 上有一些不错的 Web 技术.因此,您的 JavaScript 需要进行一些更改。我不确定你到底想做什么。但是如果你添加下面的代码

改变你的 JS:

document.getElementById('target').addEventListener('change', function () {
target = this; // get the option id selected
if (target !== null ) {
//depending on opyion selected, use its value to get the
//table/tr you want to display
document.getElementById(this.value).className = "vis";
}});

在你的 CSS 中添加:

.vis{
display: block;
}

另请查看正在运行的 JSFiddle:fiddle

关于css - 需要 html 帮助在一个唯一的选定 ID 下显示多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49016566/

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