2014-10-22 53 views
0

當用戶點擊/選擇自動完成項目時,我很難確定插入的位置以及如何進行點擊功能。然後我想用點擊的項目進行數據庫查詢。在JQuery中創建鏈接自動完成

我現在的自動完成腳本:

$("#search_customer").autocomplete({ 
     source: "search.php", 
     minLength: 1,  
     response: function(event, ui) { 
      if (!ui.content.length) { 
       var create_customer = alert('bla bla...'); 
        if (create_customer) 
        { 
        console.log('yes'); 
        } 
        else 
        { 
        console.log('no'); 
        } 
      } 
     } 
    }); 

回答

0

使用select jQuery用戶界面自動完成的回調 e.g

$("#search_customer").autocomplete({ 
     source: "search.php", 
     minLength: 1, 
     select: function(event,ui) { 
      var label = ui.item.label; // label of selected item 
      var value = ui.item.value; // value of selected item 
      // then make an ajax call here to get the data from db. 
     }, 
     response: function(event, ui) { 
      if (!ui.content.length) { 
       var create_customer = alert('bla bla...'); 
        if (create_customer) 
        { 
        console.log('yes'); 
        } 
        else 
        { 
        console.log('no'); 
        } 
      } 
     } 
    }); 

希望這有助於。

+0

正是我需要的。謝謝。 – Nomis 2014-10-22 12:51:17