[英]Html/JS: Link cell values of one column of one table from cells of another column of another table
I am new to coding and am trying to make a table using values from another table. 我是编码新手,正在尝试使用另一个表中的值创建一个表。
For example, the following table has a column for "Contact" (names) 例如,下表中的“联系人”(名称)列
<table>
<tr>
<th>Role</th>
<th>Contact</th>
<th>Email</th>
</tr>
<tr>
<td>Role1</td>
<td>Person1 </td>
<td>Person1@xyz.com</td>
</tr>
<tr>
<td>Role2</td>
<td>Person2</td>
<td>Person2@xyz.com</td>
</tr>
</table>
My second table (ttask) has a list of tasks and has a column for the "Contact" assigned to a task. 我的第二张表(ttask)有一个任务列表,并有一个分配给任务的“联系人”列。 I would like to link the value for the Contact cells in the following table with its corresponding Contact in the 1st table so that if I change the Contact's name in the 1st table, it will update in all the Table ttask cells involving that Contact's name.
我想将下表中的Contact单元格的值与其在第一张表中的相应Contact链接起来,以便如果我在第一张表中更改Contact的名称,它将在涉及该Contact名称的所有Table ttask单元格中进行更新。 How can I make this happen?
我怎样才能做到这一点?
<table id="ttask">
<tr>
<th>Weeks Prior</th>
<th>Role</th>
<th>Contact</th>
<th>Task</th>
</tr>
<tr>
<td>16</td>
<td>AH</td>
<td>Person1</td>
<td>
What currently needs to be done. The task and what's involved blah blah
</td>
</tr>
</table>
Thank you so much! 非常感谢!
first take different id for both table td and try this 首先为两个表td取不同的ID,然后尝试
$(document).ready(function(){
VAR abc = $(document.getElementById("tdidoffirsttable").innerHTML);
document.getElementById("td id of second table").innerHTML = abc;
});
The question is somewhat unclear because you didn't mention if you are willing to use html only or not. 这个问题尚不清楚,因为您没有提及您是否愿意只使用html。 If you are willing to consider javascript, then this can work:
如果您愿意考虑使用javascript,则可以使用:
<p id="demo1">person1</p>
<p id="demo2">person2</p>
<script>
function myFunction() {
var str = document.getElementById("demo2").innerHTML;
document.getElementById("demo1").innerHTML = str;
}
myFunction();
</script>
Of course this is per row, if you data contains multiple lines then should be adapted by doing a loop in order to simplify. 当然,这是每行,如果您的数据包含多行,则应进行循环调整以简化操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.