jQuery UI自动完成多个值

| 我的jQuery Autocomplete有一个奇怪的问题。 我有一个自动完成的文本框,该文本框可以检索多个值并列出它们的值,但是,我想要做的是为隐藏字段中的每个选定项目都提供另一个值。 这是我正在使用的代码:
$(\'#RecipientsList\')
    // don\'t navigate away from the field on tab when selecting an item
        .bind( \"keydown\", function( event ) {
            if ( event.keyCode === $.ui.keyCode.TAB &&
                    $( this ).data( \"autocomplete\" ).menu.active ) {
                event.preventDefault();
            }
        })
        .autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: \'<%=Url.Action(\"GetRecipients\", \"Bulletin\") %>\',
                    dataType: \"json\",
                    data: {
                        q: extractLast(request.term)
                    },
                    dataFilter: function (data) { return data; },
                    success: function (data) {
                        response($.map(data, function (item) {
                            return {
                                label: item.FirstName + \' \' + item.LastName,
                                value: item.FirstName + \' \' + item.LastName,
                                payroll: item.EmployeeNumber
                            }
                        }));
                    }
                });
            },
            search: function() {
                // custom minLength
                var term = extractLast( this.value );
                if ( term.length < 2 ) {
                    return false;
                }
            },
            focus: function() {
                // prevent value inserted on focus
                return false;
            },
            select: function( event, ui ) {
                var terms = split(this.value);
                var pterms = split($(\'#RecipientsPayrollNo\').val());
                // remove the current input
                terms.pop();
                pterms.pop();
                // add the selected item
                terms.push(ui.item.value);
                pterms.push(ui.item.payroll);
                // add placeholder to get the comma-and-space at the end
                terms.push( \"\" );
                pterms.push( \"\" );
                this.value = terms.join( \", \" );
                $(\'#RecipientsPayrollNo\').val(pterms.join( \", \" ));
                return false;
            }
        });
但是,这在Firefox中可以正常工作,但是在IE8中,每次在原始文本框中选择新值时,隐藏字段中的值都会被完全替换,尽管原始文本框会按预期工作。 我的jQuery并不是世界上最好的jQuery,因此上述内容中有些是猜测,也可能来自文档。 我想我在
$(\'#RecipientsPayrollNo\').val(pterms.join( \", \" ));
行上做错了,但我不确定。 如果有人可以提供帮助,将不胜感激。     
已邀请:
我通过将选择更改为以下内容来解决此问题:
select: function (event, ui) {
                var terms = split(this.value);
                // remove the current input
                terms.pop();
                // add the selected item
                terms.push(ui.item.value);
                // add placeholder to get the comma-and-space at the end
                terms.push(\"\");
                this.value = terms.join(\", \");
                var prollNos = $(\'#RecipientsPayrollNo\').val()
                $(\'#RecipientsPayrollNo\').val(prollNos + ui.item.payroll + \", \");
                return false;
            }
    

要回复问题请先登录注册