簡體   English   中英

jQuery自動完成以獲取未使用的值

[英]jQuery autocomplete to get unused value

在我的ASP.Net MVC應用程序中,我在文本框中具有jQuery自動完成功能。 我可以正常顯示當前使用的項目名稱,而我要強制用戶輸入一個全新的項目名稱。 也就是說,自動完成功能可作為存在內容的指南,但用戶最終必須輸入一個完全使用的字符串值。

我希望UI發出信號,指示是否選擇了當前使用的項目(發布提交時,服務器端將進行其他檢查),因此目前只有一個簡單的alert()。

我的腳本如下:

    $(document).ready(function() {
        $('#combobox').autocomplete('<%= Url.Action("ProjectIdList", "LookUp") %>', {
    delay:10,
    minChars:1,
    matchCase: 0,
    matchSubset: 1,
    autoFill: true,
    maxItemsToShow:10,
    cacheLength: 10,
    onItemSelect:selectItem,
    onFindValue:selectItem    
    });

});

請注意標記: onItemSelect:selectItem,onFindValue:selectItem

我還有其他腳本,如下所示:

    function findValue(li) {
        if (li != null) return alert("This Project Id cannot be used");


    }
    function selectItem(li) {
        findValue(li);

    }

但是, 我無法觸發這些事件 我想念什么?

另外,還有更好的方法嗎?

我用過

$("combobox").result(function(item){
  if(!item)
  {
    //no match
   }
});

官方插件取得了一些成功。

完整的最終代碼可以幫助需要幫助的人,如下所示:

    $(document).ready(function() {
        $('#combobox').autocomplete('<%= Url.Action("ProjectIdList", "LookUp") %>',
{
    delay: 10,
    minChars: 1,
    matchCase: 0,
    matchSubset: 1,
    autoFill: true,
    maxItemsToShow: 10,
    cacheLength: 10

}
);

        $('#combobox').result(function(item) {
            if (item) {
                //no match
                alert("Not this one!");
            }
        });
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM