验证自动完成文本框(请回复)



我已经在文本框中实现了自动完成。

法典:

//AutoComplete the textbox having userSearch class.
function AutoComplete() {
//Autocomplete added to the textbox.
$('.userSearch').autocomplete({
    source: function (request, response) {
        $.ajax({
            url: "CTC.aspx/GetMemberName",
            data: "{ 'prefixText': '" + request.term + "' }",
            dataType: "json",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                response(data.d);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert('Error occured while autocomplete');
            }
        });
    },
    minLength: 1,
    change: function (event, ui) { SaveData($(this).attr('id')); }
});
}

它工作正常。

但是我想限制用户,以便他必须从建议的列表中选择一个选项。

这样最终就不需要插入数据是否正确的验证函数。

请帮忙

有什么方法可以绑定用户仅从建议的列表中进行选择?

提前致谢

试试这个

change: function (event, ui) {
        if (!ui.item) {
            //Not selected from the list
        }
        SaveData($(this).attr('id'));
    }

最新更新