Jquery UI自动完成,在获得响应后选择下一个输入

时间:2012-04-02 09:02:39

标签: jquery autocomplete jquery-ui-autocomplete

我喜欢在自动完成框后选择两个输入框。 问题是自动完成后无法选择输入框。

<script>
$('.autocomplete').die('focus').live('focus', function(){
    $(this).autocomplete({
        source: 'handler.php?event=autocomplete',
        delay: 500,
        minLength: 2,
        select: function( event, ui ) {
            $(this).attr({"rel" : ui.item.id, "title" : ui.item.title});
            $.post('handler.php?event=get_details', 'id='+ui.item.id, function(ret){
                $(this).next('input').val(ret.unit);
                $(this).next('input').val(ret.min_amount);
            });
        }
    });
});

<table>
<tr>
    <td><input type="text" name="item[]" size="30" value="" class="autocomplete" /></td>
    <td><input type="text" name="unit[]" size="1" value=""></td>
    <td><input type="text" name="min_amount[]" size="5" value=""></td>
</tr>
<tr>
    <td><input type="text" name="item[]" size="30" value="" class="autocomplete" /></td>
    <td><input type="text" name="unit[]" size="1" value=""></td>
    <td><input type="text" name="min_amount[]" size="5" value=""></td>
</tr>

1 个答案:

答案 0 :(得分:0)

试试这个:

$(this)
   .parent()
   .next()
   .children('input')
   .val(ret.unit)
   .end()
   .next()
   .children('input')
   .val(ret.min_amount);