2014-03-19 20 views
0

我有下面的代碼,使用jquery ui自動完成,問題是我有困難在同一頁上設置第二個自動完成。有人可以看看代碼,並讓我知道什麼是錯的?最好的一個運行正常。有人可以看看我的jQuery UI自動完成代碼,並告訴我爲什麼它只能在1個文本框上工作嗎?

$(document).ready(function() { 

     var AccommObject = $("[id$='_txtAccommodation_txtStandard']")[0]; 
     var Accommid = AccommObject.id; 
     var AccommidFull = "#" + Accommid; 


     var AccommObject2 = $("[id$='_txtInvoiceNo_txtStandard']")[0]; 
     var Accommid2 = AccommObject2.id; 
     var AccommidFull2 = "#" + Accommid2; 



     $(AccommidFull).autocomplete({ 
      source: function(request, response) { 
       $.ajax({ 
        type: "POST", 
        contentType: "application/json; charset=utf-8", 
        url: "RequisitionSearch.aspx/FetchAccommodationNameList", 
        data: '{"AccommodationName":"' + request.term + '"}', 
        dataType: "json", 
        success: function(data) { 
         response(
         $.map(data.d, function(item) { 
          return { 
           id: item.ID, 
           label: item.Label, 
           value: item.Value, 
           ImageURL: item.ImageURL 
          }; 
         }) 
         ); 
        }, 
        error: function(result) { debugger; } 
       }); 
      }, 
      minLength: 2 
     }); 



     $(AccommidFull2).autocomplete({ 
      source: function(request, response) { 
       $.ajax({ 
        type: "POST", 
        contentType: "application/json; charset=utf-8", 
        url: "RequisitionSearch.aspx/FetchAccommodationInvoiceNoList", 
        data: '{"InvoiceNo":"' + request.term + '"}', 
        dataType: "json", 
        success: function(data) { 
         response(
         $.map(data.d, function(item) { 
          return { 
           id: item.ID, 
           label: item.Label, 
           value: item.Value, 
           ImageURL: item.ImageURL 
          }; 
         }) 
         ); 
        }, 
        error: function(result) { debugger; } 
       }); 
      }, 
      minLength: 2 
     }); 


    }); 
+0

這不是很具體。它會在控制檯中拋出一個javascript錯誤嗎? –

+0

我們可以看到HTML – Bene

+0

對不起,第二個沒有任何錯誤,它不會觸發目標方法。問題是在同一頁面上有多個自動完成實例的正確方法是什麼。由於某些原因,該事件尚未連接到第二個文本框。我已經調試過,可以看到它獲得的第二個文本框與第一個文本框完全相同,但沒有啓動。 – jazman

回答

0

這真的很煩人!部分$(「[id $ ='_ txtAccommodation_txtStandard']」)[0]使用零索引對象,但是在窗體上有一個用戶控件,它包含另一個具有完全相同擴展名的文本框,所以我所有的要做的是參考$(「[id $ ='_ txtAccommodation_txtStandard']」)[1],問題解決了!

var AccommObject = $("[id$='_txtAccommodation_txtStandard']")[0]; 
     var Accommid = AccommObject.id; 
     var AccommidFull = "#" + Accommid; 


     var AccommObject2 = $("[id$='_txtInvoiceNo_txtStandard']")[0]; 
     var Accommid2 = AccommObject2.id; 
     var AccommidFull2 = "#" + Accommid2; 
相關問題