gpt4 book ai didi

javascript - 在其他单元格之间共享一个表格单元格 HTML5

转载 作者:可可西里 更新时间:2023-11-01 13:50:38 26 4
gpt4 key购买 nike

我不确定提出问题的最佳方式,但我会尽力而为。如果我不清楚或者您需要更多信息以了解我想要实现的目标,请告诉我。

目前,我有两个表,一个包含人名(由 person1、person2 .... 表示),另一个包含评论部分。请看这里:https://dl.dropboxusercontent.com/u/53441658/peoplecomment.html .

代码:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>PersonComment</title>
</head>

<script>

function toggleTable() {
var myTable = document.getElementById("commentfield");
myTable.style.display = (myTable.style.display == "table") ? "none" : "table";
}

</script>

<body>
<table width="300" border="1" id="people" onClick="toggleTable()">
<tbody>
<tr>
<td id="cell1"><div>&nbsp;Person1</div></td>
<td id="cell2"><div>&nbsp;Person2</div></td>
</tr>
<tr>
<td id="cell5"><div>&nbsp;Person3</div></td>
<td id="cell6"><div>&nbsp;Person4</div></td>
</tr>
<tr>
<td id="cell9"><div>&nbsp;Person5</div></td>
<td id="cell10"><div>&nbsp;Person6</div></td>
</tr>
</tbody>
</table>
<table width="300" border="1" id="commentfield">
<tbody>
<tr>
<td id="comment"><div contenteditable>&nbsp;Your comment here</div></td>
</tr>
</tbody>
</table>
</body>
</html>

第一个表中包含人名的每个单元格都包含一个函数,用于打开和关闭表 2 的评论部分(评论字段)。

此表的目的当用户点击单元格时,它应该允许他们在评论部分添加评论并将该评论与他们点击的单元格绑定(bind),并且在点击时不确定该评论是否在另一个单元格上。

我想达到的目标:我想在所有人之间分享评论部分,例如,如果有人点击 person1 并发表评论,然后其他人点击 person2,我不想显示 person1 的评论,而是我想要person 能够为 person2 添加新评论。但是,例如,当我再次单击 person1 时,我希望添加到 person1 的评论显示在评论部分。

小场景:

enter image description here

屏幕截图 1 是应用程序当前的样子。带有橙色边框的屏幕截图表明有人点击了人物并添加了评论。带有绿色边框的屏幕截图表明有人点击了人物并添加了评论。带有黄色边框的屏幕截图显示有人单击了 person1 并显示了为 person1 添加的评论,然后他们单击了 person2 并显示了为 person2 添加的评论。最后一张截图显示 person2 的评论已被编辑,现在如果有人点击它,将会看到新评论。

注意:commentfield 单元格是可编辑的,因此允许人们写东西

其中一种方法是,将每个人的评论保存在可能基于单元 ID 分配给他们的变量中,并将变量值加载回评论部分。

我对编程知之甚少或一无所知,我不确定我该怎么做,欢迎任何帮助。

最佳答案

您可以包含表单标签并使用它们。

它们将有助于触发 contenteditable 可见(CSS 或 JS)


here a CSS example of the idea

input+div[contenteditable],
input[name="person"] {
position: absolute;
right: 9999px;
}
input:checked + div {
position: static;
}
label {
/* optionnal*/
display: block;
}
/* trick to simulate js toggle */

table {
position: relative;
}
[for="hide"] {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 4.7em;
background: rgba(0, 0, 0, 0.2);
pointer-events: none;
z-index: 1
}
:checked~[for="hide"] {
pointer-events: auto;
}
<form>
<table width="300" border="1" id="people" onClick="toggleTable()">
<tbody>
<tr>
<td id="cell1">
<div>
<!-- was the div usefull here ? if not; it can be avoided -->
<label for="c1">Person1</label>
</div>
</td>
<td id="cell2">
<div>
<label for="c2">Person2</label>
</div>
</td>
</tr>
<tr>
<td id="cell5">
<div>
<label for="c3">Person3</label>
</div>
</td>
<td id="cell6">
<div>
<label for="c4">Person4</label>
</div>
</td>
</tr>
<tr>
<td id="cell9">
<div>
<label for="c5">Person5</label>
</div>
</td>
<td id="cell10">
<div>
<label for="c6">Person6</label>
</div>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td id="comment" colspan="2">
<input type="radio" id="c1" name="person" />
<div contenteditable id="p1">&nbsp;Your comment here person 1</div>
<input type="radio" id="c2" name="person" />
<div contenteditable id="p2">&nbsp;Your comment here person 2</div>
<input type="radio" id="c3" name="person" />
<div contenteditable id="p3">&nbsp;Your comment here person 3</div>
<input type="radio" id="c4" name="person" />
<div contenteditable id="p4">&nbsp;Your comment here person 4</div>
<input type="radio" id="c5" name="person" />
<div contenteditable id="p5">&nbsp;Your comment here person 5</div>
<input type="radio" id="c6" name="person" />
<div contenteditable id="p6">&nbsp;Your comment here person 6</div>
<label for="hide"></label>
<input type="radio" id="hide" name="person" />
</td>
</tr>
</tfoot>
</table>
</form>

关于javascript - 在其他单元格之间共享一个表格单元格 HTML5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35130906/

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