使用JavaScript / jQuery将制表符后的字符串值剪切并粘贴到下一个输入 [英] Cut and Paste string values to next input after tab character using JavaScript/jQuery

查看:59
本文介绍了使用JavaScript / jQuery将制表符后的字符串值剪切并粘贴到下一个输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何实现,使用javascript / jquery,拆分下面列出的字符串 -

I was wondering how can I achieve, using javascript/jquery, splitting a string as listed below -

abc543567   abc543678   abc223416   abc634567

分为四个输入,这样每个组都可以移动到一个单独的输入中。基本上,当我将此字符串复制到第一个输入时,第一个组可以保留在第一个输入中,第二个组可以在第二个输入中移动,依此类推。在示例中,在组之间,我用作制表符的分隔符。以下是输入的html: https://jsfiddle.net/2sb6ggz0/

into four inputs, so that each group can be moved into a separate input. Basically, when I copy this string into the first input, the first group can remain in the first input, the second to be moved in the second input, and so on. In the example, between the groups, I used as separator the tab characters. Here is the html for the inputs: https://jsfiddle.net/2sb6ggz0/

更新HTML:

<table>
<tr>
    <td>
        <form name="form1" action="#" method="get" target="">
            <input id="input1" name="query" placeholder="Input 1" type="search" size="20">
        </form>
    </td>
    <td>
        <form name="form2" action="#" method="get" target="">
            <input id="input2" name="query" placeholder="Input 2" type="search" size="20">
        </form>
    </td> 
    <td>
        <form name="form3" action="#" method="get" target="">
            <input id="input3" name="query" placeholder="Input 3" type="search" size="20">
        </form>
    </td>
    <td>                    
        <form name="form4" action="#" method="get" target="">
            <input id="input4" name="query" placeholder="Input 4" type="search" size="20">
        </form>
    </td>
</tr>
</table>

有没有办法达到这个目的?

Is there a way top achieve this?

推荐答案

这是您更新的小提琴: https://jsfiddle.net/ 2sb6ggz0 / 6 /

Here is your updated fiddle: https://jsfiddle.net/2sb6ggz0/6/

function split(sep, clazz) {

    var items = $(clazz);

    items.each(function (i) {

        $(this).on("paste", function () {
            var me = $(this);
            setTimeout(function () {
                var splitted = me.val().split(sep);
                items.each(function (i) {
                    $(this).val(splitted[i]);
                });
            }, 1);
        });
    })
};    
split("-", ".query-input")

这篇关于使用JavaScript / jQuery将制表符后的字符串值剪切并粘贴到下一个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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