1

我正在使用 jquery 自动完成功能。我已将此应用于以特定 id 开头的所有文本框,并根据当前文本框值过滤响应。但不要得到价值。下面是我的代码。

$("input[id^='TextBoxAssociate']").autocomplete(
    {
        source: function (request, response) {
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "CreateEditRequest.aspx/GetEmpNames",
                data: "{'empName':'" + $(this).val() + "'}", // here $(this) is ajax context, I want value of current textbox
                dataType: "json",
                success: function (data) {
                    response($.map(data.d, function (el) {
                        return {
                            label: el.EmpName,
                            value: el.EmpId
                        };
                    }));
                },
                error: function (result) {
                    alert("Error");
                }
            });
        }
4

1 回答 1

0
    $("input[id^='TextBoxAssociate']").autocomplete(
        {
            source: function (request, response) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "CreateEditRequest.aspx/GetEmpNames",
                    data: "{'empName':'" + $(this).val() + "'}", // here $(this) is ajax context, I want value of current textbox
                    dataType: "json",
                    success: function (data) {
                        response($.map(data.d, function (el) {
                            return {
                                label: el.EmpName,
                                value: el.EmpId
                            };
                        }));
                    },
                    error: function (result) {
                        alert("Error");
                    },
    select: function (event, ui) {
            var label = ui.item.label;
            var value = ui.item.value;
alert('Label : ' + label );
alert('Value : ' + value );
        }
                });
            }
于 2013-11-11T14:05:22.190 回答