如何使用输入复制和粘贴excel列到HTML表?
问题描述:
我想将excel列或任何类似的列表复制并粘贴到HTML表格中。我有这个代码,但有一个问题。它像行一样粘贴数据。那么如何将其更改为像列一样粘贴?在此先感谢。
我尝试过:
I want to copy and paste excel columns or any similar lists into HTML table. I have this code, but there is a issue. It pastes data like a row. So how can I change It to paste like a column? Thanks in advance.
What I have tried:
<pre><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
</head>
<body>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
</thead>
<tbody>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
<tr>
<td><input type="text"></td>
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
</tbody>
</table>
<script>
$(document).ready(function() {
$('td input').bind('paste', null, function (e) {
$this = $(this);
setTimeout(function () {
var columns = $this.val().split(/\s+/);
var i;
var input = $this;
for (i = 0; i < columns.length; i++) {
input.val(columns[i]);
if( i % 3 !== 2){
input = input.parent().next().find('input');
} else{
input = input.parent().parent().next().find('input');
}
}
}, 0);
});
} );
</script>
</body>
</html>
答
( document )。ready( function (){
(document).ready(function() {
(' td input')。bind(' paste', null , function (e) {
('td input').bind('paste', null, function (e) {
this =