简体   繁体   English

jQuery从Excel复制到多个输入字段

[英]jQuery copy from Excel to multiple input fields

I have na excel sheet with the data: 我没有数据的Excel表:

English | Spanish | Italian | French

I'd like to be able to copy all these inputs and paste it to the form: 我希望能够复制所有这些输入并将其粘贴到表单中:

<input type="text" name="english">
<input type="text" name="spanish">
<input type="text" name="italian">
<input type="text" name="french">

so far when I copy all the data it will all paste into first input field. 到目前为止,当我复制所有数据时,它将全部粘贴到第一个输入字段中。 I'm asking this before I start coding as I'm not sure if it's even possible to do. 我在开始编码之前就问这个问题,因为我不确定是否可以这样做。

Any directions appreciated! 任何方向表示赞赏!

The clipboard is not going to allow this. 剪贴板将不允许这样做。 You might want to look into a library like HandsOnTable which will parse the clipboard/excel data and run the paste into multiple inputs. 您可能想要查看类似HandsOnTable的库,该库将解析剪贴板/ excel数据并将粘贴运行到多个输入中。

http://handsontable.com/ http://handsontable.com/

Upon your clarification, you can use jQuery to capture the paste action into anyone of those fields. 在澄清之后,您可以使用jQuery将粘贴操作捕获到这些字段中的任何一个中。 Then simply parse and send it to the right input box. 然后只需解析并将其发送到正确的输入框即可。

HTML 的HTML

<input type="text" name="english">
<input type="text" name="spanish">
<input type="text" name="italian">
<input type="text" name="french">

jQuery jQuery的

$('input').bind('paste', null, function(e){
    $this = $(this);

    setTimeout(function(){
        var columns = $this.val().split(/\s+/);
        $this.val(' ');
        var i;

        for(i=0; i < columns.length; i++){
            var name = columns[i].toLowerCase();
            $('input[name="' + name + '"]').val(columns[i]);
        }
    }, 0);
});

Here's a demo fiddle to look at : http://jsfiddle.net/adjit/3N94L/3/ 这里是一个演示小提琴: http : //jsfiddle.net/adjit/3N94L/3/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM