如何使用输入复制和粘贴excel列到HTML表? [英] How copy and paste excel columns to HTML table with inputs?

查看:74
本文介绍了如何使用输入复制和粘贴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>

推荐答案

(< span class =code-sdkkeyword> document )。ready( function (){
(document).ready(function() {


' td input')。bind(' < span class =code-string> paste', null function (e) {
('td input').bind('paste', null, function (e) {


this =


这篇关于如何使用输入复制和粘贴excel列到HTML表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆