欧美成人精品手机在线观看_69视频国产_动漫精品第一页_日韩中文字幕网 - 日本欧美一区二区

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

js將一個table的某列轉(zhuǎn)移到另一個table的上

liguoquan
2025年4月19日 15:50 本文熱度 131
:js將一個table的某列轉(zhuǎn)移到另一個table的上


<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title></title>

</head>

<script>

function moveTableColumn(sourceTableId, targetTableId, columnIndex) {  

  // 1. 獲取源表格和目標(biāo)表格  

  const sourceTable = document.getElementById(sourceTableId);  

  const targetTable = document.getElementById(targetTableId);  

  // 2. 校驗表格和列是否存在  

  if (!sourceTable || !targetTable) {  

    console.error("Source or target table not found.");  

    return;  

  }  

  const sourceRows = sourceTable.rows;  

  if (sourceRows.length === 0) {  

    console.warn("Source table is empty.");  

    return;  

  }  

  if (columnIndex < 0 || columnIndex >= sourceRows[0].cells.length) {  

    console.error("Invalid column index.");  

    return;  

  }  

  // 3. 遍歷源表格的每一行,將指定列的單元格移動到目標(biāo)表格的對應(yīng)行  

  for (let i = 0; i < sourceRows.length; i++) {  

    const sourceRow = sourceRows[i];  

    const sourceCell = sourceRow.cells[columnIndex];  

    // 確保目標(biāo)表格的行數(shù)足夠,如果不夠則創(chuàng)建新的行  

    if (targetTable.rows.length <= i) {  

      const newTargetRow = targetTable.insertRow(); // 在末尾插入新行  

    }  

    const targetRow = targetTable.rows[i];  

    // 將源單元格添加到目標(biāo)表格的行中  

    targetRow.appendChild(sourceCell);  // 移動單元格  

    // 如果需要復(fù)制單元格,而不是移動,使用以下代碼:  

    // const clonedSourceCell = sourceCell.cloneNode(true); // 克隆節(jié)點(包含子節(jié)點)  

    // targetRow.appendChild(clonedSourceCell);  

  }  

  // 4. (可選) 移除源表格的空列 (不建議,可能破壞表格結(jié)構(gòu))  

  // 如果你確實想要移除空列,必須在遍歷后進(jìn)行,并考慮表格結(jié)構(gòu)。  

  //  移除空列的代碼會比較復(fù)雜,因為需要考慮合并單元格等情況。  

  //  通常更好的做法是隱藏源表格的列,而不是直接移除。  

}  

</script>

<body>

<table id="sourceTable" border="1">  

  <thead>  

    <tr>  

      <th>Column 1</th>  

      <th>Column 2</th>  

      <th>Column 3</th>  

    </tr>  

  </thead>  

  <tbody>  

    <tr>  

      <td>Row 1, Col 1</td>  

      <td>Row 1, Col 2</td>  

      <td>Row 1, Col 3</td>  

    </tr>  

    <tr>  

      <td>Row 2, Col 1</td>  

      <td>Row 2, Col 2</td>  

      <td>Row 2, Col 3</td>  

    </tr>  

  </tbody>  

</table>  

<table id="targetTable" border="1">  

<thead> <tr> <th>New Column</th> </tr> </thead> <tbody> </tbody> </table>

<button onclick="moveTableColumn('sourceTable', 'targetTable', 1)">Move Column 2</button>

</body>

</html>


該文章在 2025/4/19 15:50:21 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運作、調(diào)度、堆場、車隊、財務(wù)費用、相關(guān)報表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點,圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務(wù)都免費,不限功能、不限時間、不限用戶的免費OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved