[英]How to move cell data values from one column to another in HTML table with Javascript?
[英]Html/JS: Link cell values of one column of one table from cells of another column of another table
我是編碼新手,正在嘗試使用另一個表中的值創建一個表。
例如,下表中的“聯系人”(名稱)列
<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>
我的第二張表(ttask)有一個任務列表,並有一個分配給任務的“聯系人”列。 我想將下表中的Contact單元格的值與其在第一張表中的相應Contact鏈接起來,以便如果我在第一張表中更改Contact的名稱,它將在涉及該Contact名稱的所有Table ttask單元格中進行更新。 我怎樣才能做到這一點?
<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>
非常感謝!
首先為兩個表td取不同的ID,然后嘗試
$(document).ready(function(){
VAR abc = $(document.getElementById("tdidoffirsttable").innerHTML);
document.getElementById("td id of second table").innerHTML = abc;
});
這個問題尚不清楚,因為您沒有提及您是否願意只使用html。 如果您願意考慮使用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>
當然,這是每行,如果您的數據包含多行,則應進行循環調整以簡化操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.