简体   繁体   English

HTML / JS:链接一个表的一列的单元格值与另一表的另一列的单元格的链接

[英]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.

相关问题 如何使用Javascript将单元格数据值从HTML表格的一列移到另一列? - How to move cell data values from one column to another in HTML table with Javascript? HTML / JS从另一个表单元格更新一个表单元格 - HTML/JS Update one table cell from another table cell 列的值从一个表转移到另一个表 - Transfer Values of a Column from One Table to Another 选择html表的某些行,然后在单击链接时将所选行的一列的值发送到另一个php页面 - Select some rows of a html table and sent the values of one column of selected rows to another php page when clicking a link jQuery Datatable将一列从一个表拖放到另一个表 - Jquery Datatable drag and drop a column from one table to another 更改一列时如何更新HTML表格行中的单元格? - How to update cells in the HTML Table row when change one column? 通过单击另一个表中的单元格来删除表中的列 - Delete column in a table by clicking cell in another table jQuery:根据另一列的属性更新一个表列上的CSS - jquery : update css on one table column based on attribute of another column jQuery,在表中单击超链接值时,将其从一个单元格复制到同一行中的另一个单元格 - jQuery, Copy hyper-link value when clicked on it in table from one cell to another in the same row 如果另一列包含目标词,则从一个表列中收集数据 - Scraping data from one table column if another column contains target words
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM