- 注册时间
- 2011-3-21
- 最后登录
- 2022-3-22
- 在线时间
- 1191 小时
- 阅读权限
- 200
- 积分
- 9457
- 帖子
- 1256
- 精华
- 0
- UID
- 1
|
建两个页面:import.htm, edit.htm, 运行 import.htm
edit.htm- <html>
- <head><script>window.onload = function() { document.designMode = 'on'; };</script></head>
- <body contenteditable="true"></body>
- </html>
复制代码 import.htm- <script>
- function importData() {
- var xlsDoc = document.getElementById('dataTable').contentWindow.document;
- var tables = xlsDoc.getElementsByTagName('table');
- if (!tables.length) {
- return alert('没有粘贴数据');
- }
- var dataTable = tables[0];
- var myTab = document.getElementById('myTab');
- for (var i=0; i<myTab.rows.length; i++) {
- if (dataTable.rows.length <= i) break;
- var mRow = myTab.rows[i];
- var dRow = dataTable.rows[i];
- for (var j=0; j<mRow.cells.length; j++) {
- if (dRow.cells.length <= j) break;
- var mCell = mRow.cells[j];
- var dCell = dRow.cells[j];
- mCell.getElementsByTagName('input')[0].value = dCell.innerText||dCell.textContent||'';
- }
- }
- xlsDoc.body.innerHTML = '';
- }
- </script>
- <form>
- <table border="1" id="myTab">
- <tr>
- <td><input /></td>
- <td><input /></td>
- <td><input /></td>
- <td><input /></td>
- <td><input /></td>
- </tr>
- <tr>
- <td><input /></td>
- <td><input /></td>
- <td><input /></td>
- <td><input /></td>
- <td><input /></td>
- </tr>
- <tr>
- <td><input /></td>
- <td><input /></td>
- <td><input /></td>
- <td><input /></td>
- <td><input /></td>
- </tr>
- </table>
- 表格数据粘贴在下面的框框中, 然后<input type="button" onclick="importData();" value="导入..." />后续的表单验证提交什么的... 不废话了<br/>
- <iframe src="edit.htm" id="dataTable" ></iframe>
- </form>
复制代码 |
|