3

我使用 jQuery UI 在页面上有一个自动完成功能,这里是 JSON:

[ {"label":"test1", "value":"1"},
  {"label":"testtest", "value":"6"},
  {"label":"test2", "value":"8"} ]

自动完成的默认操作将抓取项目的值并放入输入框中。有什么办法可以阻止它吗?而是有两个单独的操作:一个注入到隐藏框(带有值),另一个注入到带有(标签)的输入框。

$.getJSON('index.php?controller=account&action=getusers', function(data) {
    tempJson = data;

    $(".auto-search").autocomplete({
        minLength: 2,
        dataType: 'json',
        source: tempJson,
        select: function (event,ui) {
            $('input[name="user-id"]').val(ui.item.value);
        }
    });
});
4

2 回答 2

8

你的意思是这样的:

........
select: function (event,ui){
    $('input[name="user-id"]').val(ui.item.label);
    $('input[name="your-hidden-field"]').val(ui.item.value);
    return false;
}
于 2012-12-09T05:07:28.130 回答
0

这是组合框脚本创建的实际 HTML:

    <p class="dlgline">Select activity:<br>
        <select id="biActivity_id" style="display: none;"><option value="1">2015/12/23 14:26 for 1 hour, 3 minutes, Demo</option></select>
        <span class="custom-combobox"><input title="" class="custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left ui-autocomplete-input" autocomplete="off"><a tabindex="-1" title="Show All Items" class="ui-button ui-widget ui-state-default ui-button-icon-only custom-combobox-toggle ui-corner-right" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-s"></span><span class="ui-button-text"></span></a></span>
    </p>
    <p class="dlgline">Select project:<br>
        <select id="biProj_id" style="display: none;"><option value="1">Productive Non Contract</option><option value="2">Non Project Sales</option><option value="3">Waiting Time</option><option value="5">BEL SEM gateway</option><option value="6">Electronic Timesheets</option><option value="7">Fieldbus Speed Module</option><option value="8">Power Management Systems Design</option></select><span class="custom-combobox"><input title="" class="custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left ui-autocomplete-input" autocomplete="off"><a tabindex="-1" title="Show All Items" class="ui-button ui-widget ui-state-default ui-button-icon-only custom-combobox-toggle ui-corner-right" role="button"><span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-s"></span><span class="ui-button-text"></span></a></span>
    </p>
于 2015-12-23T19:11:00.403 回答