自动完成动态创建的投入 [英] autocomplete for dynamically created inputs

查看:100
本文介绍了自动完成动态创建的投入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

信息了!和Java中的小白*什么!

first post! and a noob in java*whatever!

我知道有关于这个话题很多帖子,我读过他们。我只是无法得到它解决。

I know there are many posts regarding this topic, I've read them.. I just can't get it solved.

我有一个静态输入和动态创建的投入非常简单的HTML表单。

I have very simple HTML form with statics inputs and dynamically created inputs.

HTML自动完成

    <script type="text/javascript">
    // Funcion Autocomplete de jQuery para buscar los clientes y los productos en el input con id "buscar" y clase "buscar_prod"
    $().ready(function() {
        $("#buscar").autocomplete("get_client_list.php", {
            width: 260,
            matchContains: true,
            selectFirst: false
        });
    });
    $().ready(function() {
        $(".buscar_prod").autocomplete("get_product_list.php", {
            width: 260,
            matchContains: true,
            selectFirst: false
        });
    });
</script>

HTML表单

<form method="post" action="add_order.php">

 Cliente: <input type="text" name="cliente" id="buscar">

 <div id="dynamicInput">
      Referencia y cantidad <br><input type="text" class="buscar_prod" name="input_referencia[]"><input type="text" name="input_cantidad[]">
 </div>
 <input type="button" value="Adicionar otra referencia" onClick="addInput('dynamicInput','order');">
 <input type="submit" name="guardar" value="Guardar" />

addInput.js


var counter = 1;

function addInput(divName,category){
    switch(category){
    case "order":
        var newdiv = document.createElement('div');
        newdiv.innerHTML = "Referencias y cantidad " + (counter + 1) + " 
"; document.getElementById(divName).appendChild(newdiv); counter++; break; case "product": var newdiv = document.createElement('div'); newdiv.innerHTML = "Componente y cantidad " + (counter + 1) + "
"; document.getElementById(divName).appendChild(newdiv); counter++; break; case "component": var newdiv = document.createElement('div'); newdiv.innerHTML = "Proveedor y Precio " + (counter + 1) + "
"; document.getElementById(divName).appendChild(newdiv); counter++; break; } }

所以,问题很简单,..考虑到这些codeS,我怎么可能实现每一个新产生的输入自动完成。

So question is simple,.. given these codes, how could I implement the autocomplete in each new generated input.

提前非常感谢。

推荐答案

您可以将自动完成您所添加的元素到DOM后,如:

You can attach the autocomplete after you have added the element to the DOM, like:

$(newdiv).autocomplete("get_client_list.php", {
    width: 260,
    matchContains: true,
    selectFirst: false
});

您可以根据您的switch-case语句调用特定的自动完成code。

you can call the specific autocomplete code according to your switch-case statement.

这篇关于自动完成动态创建的投入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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