这看起来很简单,但我似乎不能让它工作:
var options, a;
jQuery(function(){
  options = { 
  serviceUrl:'ajax/parts_by_partno.php', 
  select: function(event, ui) { 
    $("#hiddenId").val(ui.item.id); 
    }
  };
  a = $('#fieldWithData').autocomplete(options);
});从自动完成列表中选择项目后,我希望#hiddenId将其值更改为所选项目的ID:
$("#hiddenId").val(ui.item.id); 我甚至试着把#hiddenId改成像这样的静态代码:
$("#hiddenId").val('test'); 什么都没变。我做错了什么?
发布于 2012-03-14 12:24:40
看看这个code..hope,它会对你有帮助的
$('#selector').autocomplete({
    source: url,
    select: function (event, ui) {
        $("#txtAllowSearch").val(ui.item.label); // display the selected text
        $("#txtAllowSearchID").val(ui.item.value); // save selected id to hidden input
    }
});
$('#button').click(function() {
    alert($("#txtAllowSearchID").val(); // get the id from the hidden input
}); 发布于 2012-03-14 12:26:58
以下是有关如何使用自动完成模块的full blog entry
基本上,当select值改变时,您需要添加一个回调,如下所示:
 select: function(e, ui) {  
        //create formatted friend  
        var friend = ui.item.value,  
            span = $("<span>").text(friend),  
            a = $("<a>").addClass("remove").attr({  
                href: "javascript:",  
                title: "Remove " + friend  
            }).text("x").appendTo(span);  
            //add friend to friend div  
            span.insertBefore("#to");  
        },  
        //define select handler  
        change: function() {  
            //prevent 'to' field being updated and correct position  
            $("#to").val("").css("top", 2);  
        }  
    });  https://stackoverflow.com/questions/9695854
复制相似问题