简体   繁体   English

jQuery的自动完成输入数组

[英]jquery autocomplete with input array

I am using the following formular: 我正在使用以下公式:

ROW1: <input class="search" name="pos[]" value=""><input name="str[]" value="">
ROW2: <input class="search" name="pos[]" value=""><input name="str[]" value="">
ROW3: <input class="search" name="pos[]" value=""><input name="str[]" value="">

For the first input of each row I activated jquery autocomplete: 对于每行的第一个输入,我激活了jQuery自动完成功能:

$(".search").autocomplete(ac_new_invoice);
var ac_new_invoice = {
    source: "productsearch.php",
    minLength:1,
    select: function(data){
        var str = document.forms[0].elements["str[]"];
        str[1].value = '1.000,00';
    }
}

So it works fine when I type 所以当我打字的时候效果很好

 str[1].value = '1.000,00';

But what i want is that if I type in row 1 the input str in row 1 will be changed. 但是我想要的是,如果我在第1行中键入,则第1行中的输入str将会更改。 But how do I get the row in which the autocomplete is performed from? 但是,如何获得执行自动完成的行?

Thanks in advance! 提前致谢!

Rather than apply autocomplete to all the elements at once, you can call it on each element. 您可以在每个元素上调用自动完成功能,而不是一次对所有元素应用自动完成功能。

$('.search').each(function (i) {
    var ac_new_invoice = (function (i) {
        return {
            source: "productsearch.php",
            minLength: 1,
            select: function (data) {
                var str = document.forms[0].elements["str[]"];
                str[i].value = '1.000,00';
            }
        };
    })(i);
    $(this).autocomplete(ac_new_invoice);
});

Note that you'll need (function (i){ blabla })(i) to make a immediate copy of the variable i . 请注意,您需要(function (i){ blabla })(i)来立即复制变量i

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

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