0

我有一个使用 jquery 的自动完成文本框。

如果用户键入 3 个字符,则显示来自 DB 的列表。我的问题是如果用户键入他自己的东西并提交我需要警告他或触发一些验证消息?

我该怎么做呢 ?

如果用户输入 Own thing 表示 --- 例如

我在数据库中有以下建议列表,例如

Apple Orange Grapes,我不希望用户输入 Gra 或 app 或 DB 中不存在的 tat sort

4

1 回答 1

0

调用自动完成时可以使用selectchange事件处理程序。

例如:

$('#autocomplete').autocomplete({
    minLength: 3,
    source: 'getlist.php', // for example
    select: function(event, ui) {
        // the user selected from drop-down
    },
    change: function(event, ui) {
        // the user input his own values..

        // $(this).val(''); // this code will reset the value to blank
    }
});
于 2013-02-28T09:25:11.040 回答