2015-05-08 52 views
0

我試圖用jQuery自動完成搜索客戶數據。我有以下情況。jQuery自動完成選擇標籤和值,並只顯示標籤

客戶姓名和手機號碼應顯示爲列表選擇和選擇,我只能將客戶名稱顯示爲自動填充文本框。

我試過下面的代碼,但它不會工作。

$("#txtServiceCustSearch").autocomplete(
      {   
       source: function (request, response) { 
        $.ajax({ 
         url: '<%=ResolveUrl("~/AutoComplete.asmx/GetServiceCustomer") %>', 
         data: "{ 'prefix': '" + request.term + "'}", 
         dataType: "json", 
         type: "POST", 
         contentType: "application/json; charset=utf-8", 
         success: function (data) { 
          $("[id*='grvHistory']").empty(); 
          response($.map(data.d, function (item) {        
           return { 
            label: item.split('$')[0], 
            val: item.split('$')[1], 
            val1: item.split('$')[2], 
            val2: item.split('$')[3], 
            val3: item.split('$')[4], 
            val4: item.split('$')[5], 
            val5: item.split('$')[6], 
            val6: item.split('$')[7], 
            val7: item.split('$')[8] 
           } 
          })) 
         }, 
         error: function (response) { 
          alert(response.responseText); 
         }, 
         failure: function (response) { 
          alert(response.responseText); 
         } 
        }); 
       }, 
       select: function (e, i) { 
        $("#txtServiceAddress").val(i.item.val); 
        $("#txtPinCode").val(i.item.val1); 
        $("#txtServiceContactNo").val(i.item.val2); 
        $("#txtLandmark").val(i.item.val3); 
        $("#txtEmailID").val(i.item.val4); 
        $("#txtServiceDOB").val(i.item.val5); 
        $("#txtServiceMobileNo").val(i.item.val6); 
       $("#txtServiceCustSearch").val(i.item.val7); }, 
       close: function (e, i) { 
       }, 
       minLength: 3 
      }); 

回答

0

選擇添加

 e.preventDefault()
:功能(E,I)

相關問題