gpt4 book ai didi

javascript - Javascript 中的表格 - 隐藏/显示列

转载 作者:行者123 更新时间:2023-11-30 10:06:10 25 4
gpt4 key购买 nike

我已经搜索了好几个小时,但没能找到像我这样创建的表格,其中有隐藏/显示实例 - 我已经尝试对标准 HTML 表格使用一些标准的隐藏/显示,但它没有'不要像我需要的那样翻译过来工作。

我有一个用 JS 创建的表,它从 json 加载数据,看起来像:

var output = "<table class = sample>",

tableHeadings = "<thead>" +

//set column names
"<tr>" +
"<th></th>" +
"<th><u>Name:</u></th>" +
"<th><u>Address:</u></th>" +
"<th><u>City:</u></th>" +
"<th><u>State:</u></th>" +
"<th><u>Phone Number:</u></th>" +
"<th><u>PO:</u></th>" +
"<th><u>Stuff:</u></th>" +
"<th><u>Stuff:</u></th>" +
"<th><u>Stuff:</u></th>" +
"<th><u>Stuff:</u></th>" +
"<th><u>Stuff:</u></th>" +
"</tr>" +
"</thead>";
output += tableHeadings;

output += "<td>"+'<a href="#" onclick="javascript:displayInfobox(' + (i) + ');">' + results[i]["Business Name"] +'<\/a>' + "</td>" +
"<td>" + results[i]["Address"] + "</td>" +
"<td><center>" + results[i]["City"] + "</center></td>" +
"<td><center>" + results[i]["StateListing"] + "</center></td>";

document.getElementById("placeholder").innerHTML = output;

我想做的是使用按钮/复选框隐藏/显示地址栏。我试过在 jquery 中使用 style.display 和 .hide/.show。我尝试的所有操作都会隐藏第一个条目,但仍会显示之后每个条目的地址。

我需要能够隐藏显示的所有条目的命令地址信息。

最佳答案

您可以使用子选择器:

$("td:nth-child(2)").hide()

或者在你的地址td中添加一个类,并选择所有的c类:

<td class='c'>
$(".c").hide()

关于javascript - Javascript 中的表格 - 隐藏/显示列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29041583/

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