当我选择一个单元格时,表格会打开另一个表格HTML
问题描述:
我需要帮助,因为我需要创建一个表格来选择单元格时打开另一个表格。我需要在HTML或JavaScript中执行此操作。当我选择一个单元格时,表格会打开另一个表格HTML
我有一个表有一些单元格有数据,当我选择其中一个时,我需要其他表格与其他数据打开下面。
有人能给我一个想法,我该如何做到这一点?
答
你可以做的一件事是让其他表已经在它下面,用CSS将display
更改为none
,然后让它在稍后用JavaScript执行。这里是我的代码在JQuery中完成:
$("#tableOne").click(function() {
$("#tableTwo").css("display", "block");
});
#tableTwo {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id = "tableOne">
<tr>
<td>
<button id = "demo">Click Me!</button>
</td>
</tr>
</table>
<table id = "tableTwo">
<tr>
<td>
<p>Yay!</p>
</td>
</tr>
</table>
这里是我的常规的JavaScript:
var demo = document.getElementById("demo");
demo.onclick = function() {
document.getElementById("tableTwo").style.display = "block";
}
#tableTwo {
display: none;
}
<table id = "tableOne">
<tr>
<td>
<button id = "demo">Click Me!</button>
</td>
</tr>
</table>
<table id = "tableTwo">
<tr>
<td>
<p>Yay!</p>
</td>
</tr>
</table>
答
<html>
<head>
<script>
function displaySecondTable(){
document.getElementById("tableTwo").innerHTML=" (here is the code for your second table) ";
}
</script>
</head>
<body>
<table id = "tableOne">
<tr>
<td onclick="displaySecondTable()">
Click here
</td>
</tr>
</table>
<table id = "tableTwo" />
</body>
</html>
可以在纯JavaScript做;)
非常感谢,兄弟。 这段代码让我省却了很多麻烦,并为我在办公室的活动提供了一个灯光。 非常感谢! –