【问题标题】:Autocomplete Jquery Multiple Rows自动完成 Jquery 多行
【发布时间】:2014-10-04 15:56:23
【问题描述】:

我有一个包含多行和多列的表,但我不知道如何使用 Jquery 的自动完成插件,以便仅自动完成选定的行。是表代码:

<table class="participante estilizar" id="participante_<?php echo $i?>" cellspacing="0" width="100%">
    <tbody>
        <tr>
            <td>
                <label for="cedula">Cédula</label><input class="cedula" onkeypress="return numeros(event)" type="text" maxlength="50" name="participante_cedula[]" value="<?php echo $value->cedula?>" />
            </td>
            <td>
                <label for="nombre">Nombre y apellido</label><input class="nombre" onkeypress="return alfa(event)" type="text" maxlength="75" name="participante_nombre[]" value="<?php echo $value->nombre?>" />
            </td>
            <td>
                <label for="correo">Correo</label><input class="correo" type="text" maxlength="50" name="participante_correo[]" value="<?php echo $value->correo?>" />
            </td>
        </tr>
    </tbody>
</table>

我知道我应该使用标签 id 来识别表格的每一行,但在这种情况下,我不知道如何调用自动完成插件。这是自动完成代码:

var sug_cedula = [
    {
        label: "123",
        nombre: "Juan",
        correo: "juan@cuenta.com"
    },
    {
        label: "456",
        nombre: "Pedro",
        correo: "pedro@cuenta.com"
    },
    {
        label: "789",
        nombre: "Angel",
        correo: "angel@cuenta.com"
    }
];
$( ".cedula" ).autocomplete({
    minLength: 0,
    source: sug_cedula,
    focus: function( event, ui ) {
        return false;
    },
    select: function( event, ui ) {
        $( ".cedula" ).val( ui.item.label );
        $( ".nombre" ).val( ui.item.nombre );
        $( ".correo" ).val( ui.item.correo );
        return false;
    }, 
});

在我的示例中,当我键入一些字符并选择一个选项时,该函数会自动完成所有具有相同值的表,因为我使用的是标记类而不是标记 ID。有人可以帮我吗?

【问题讨论】:

    标签: javascript jquery autocomplete rows multiple-columns


    【解决方案1】:

    如果你只想设置当前行的当前值,你可以这样做:

    $( ".cedula" ).autocomplete({
       minLength: 0,
       source: sug_cedula,
       focus: function( event, ui ) {
           return false;
       },
       select: function( event, ui ) {
        var thisRow = $(this).parents("tr");
        thisRow.find(".cedula").val( ui.item.label );
        thisRow.find(".nombre").val( ui.item.nombre );
        thisRow.find(".correo").val( ui.item.correo );
        return false;
       }, 
    });
    

    【讨论】:

    • 感谢您的帮助,它确实对我有用,我只需要在使用您的选项之前添加此代码:code var thisRow = $(this).closest('tr');
    猜你喜欢
    • 2017-05-08
    • 2018-01-29
    • 2018-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多