| js如何在一页面加载出另一个页面的一个table内容
					当前位置:点晴教程→知识管理交流
					
					→『 技术文档交流 』
					
				 
  :js如何在一页面加载出另一个页面的一个table内容  <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <div id="get_table_value"></div> </body> <script> // 假设你想要加载的页面URL是'sourcePageUrl',表格的ID是'tableId' const sourcePageUrl = 'sourcePage.html'; const tableId = 'middleTable'; fetch(sourcePageUrl) .then(response => response.text()) .then(html => { // 解析HTML字符串,创建DOM元素 const parser = new DOMParser(); const doc = parser.parseFromString(html, 'text/html'); 
 // 从解析后的文档中获取表格 const table = doc.getElementById(tableId); 
 // 检查表格是否存在 if (table) { // 将表格添加到当前页面的某个元素中 //document.body.appendChild(table.cloneNode(true) document.getElementById("get_table_value").appendChild(table.cloneNode(true) ); } else { console.error('Table not found'); } }) .catch(error => { console.error('Error fetching the page:', error); }); 
 </script> </html> 该文章在 2024/12/16 16:35:11 编辑过 | 关键字查询 相关文章 正在查询... |