2016-12-02 86 views
-1

代码的第一部分用于在gridview中创建多个文本框。文本框键盘事件的自动完成功能

在第二部分中,我想对文本框keyup事件使用自动完成功能。

第二部分不起作用。

$(function() { 
      $('#cpContent_grdOrderDetail tr').attr('data-count', '0'); 
      $('.bull').click(function() { 
       var NewRow = $(this).closest('tr'); 
       var SrNo = $(this).closest('tr').find('.GridTextBox').val(); 
       var no = parseInt(NewRow.attr('data-count')); 
       var newx = no + 1; 
       NewRow.attr('data-count', newx); 
       var ProductId = $(this).closest('tr').find('#hfProductId').val(); 
       $(this).closest('tr').find('#hfAttachmentCount').val(no); 
       alert(ProductId); 
       var content = '<tr><td></td>'; 
       content = content + '<td><input type="text" ID="txtAttachmentCode' + SrNo + '_' + no + '" class="AttachmentAutoFill" /><input type="hidden" class="AttachPId" ID="hfProductId' + SrNo + '_' + no + '" Value=' + ProductId + ' /></td>'; 
       content = content + '<td><input type="text" ID="txtAttachName' + SrNo + '_' + no + '" /></td>'; 
       content = content + '<td colspan=2></td>'; 
       content = content + '<td><input type="text" ID="txtAttachmentQty' + SrNo + '_' + no + '"/></td>'; 
       content = content + '<td><input type="text" ID="txtAttachCost' + SrNo + '_' + no + '"/></td>'; 
       content = content + '<td colspan=3></td>'; 
       content = content + '<td><input type="text" ID="txtAttachmentTotalCost' + SrNo + '_' + no + '"/></td>'; 
       content = content + '</tr>'; 
       $(content).insertAfter(NewRow); 
       return false; 
      }); 

      $(document).on('keyup', '.AttachmentAutoFill', function() { 
       var ProductId = $(this).next('.AttachPId').val(); 
       var FilterText = $(this).val(); 
       $(this).autocomplete({ 
        source: function (request, response) { 
         $.ajax({ 
          url: '<%=ResolveUrl("~/WebService/GetItemsForAutoCompleteBox.asmx/GetAttachmentInfo") %>', 
          data: "{ 'ProductId': '" + $(this).next('.AttachPId').val() + "',FilterText'" + $(this).val() + "'}", 
          dataType: "json", 
          type: "POST", 
          contentType: "application/json; charset=utf-8", 
          success: function (data) { 
           response($.map(data.d, function (item) { 
            return { 
             label: item.split('-')[0], 
             val: item.split('-')[1] 
            } 
           })) 
          }, 
          error: function (response) { 
           alert(response.responseText); 
          }, 
          failure: function (response) { 
           alert(response.responseText); 
          } 
         }); 
        }, 
        select: function (e, i) { 

        }, 
        minLength: 1 
       }); 
      }); 
     }); 
+0

是否有任何错误? –

+0

没有任何错误的问题是它不去内自动完成功能,即$(this).autocomplete({ – grnake

+0

添加您的html标记到您的问题或使小提琴 –

回答

0

没有与当你将数据发送到您的要求,您拨打$(this).next('.AttachPId')但里面$阿贾克斯$(本)您的AJAX调用的一个问题,所以你需要将其保存的范围是不是指输入框和那么你可以在ajax里面使用它。

$(document).on('keyup', '.AttachmentAutoFill', function() { 
     var ProductId = $(this).next('.AttachPId').val(); 
     var FilterText = $(this).val(); 
     var postData = {'ProductId':ProductId,'FilterText':FilterText}; 
     $(this).autocomplete({ 
      source: function (request, response) { 
       $.ajax({ 
        url: '<%=ResolveUrl("~/WebService/GetItemsForAutoCompleteBox.asmx/GetAttachmentInfo") %>', 
        data: postData , 
        // other config stuff 
        success: function (data) { 
         // your success callback goes here 
        }, 
        error: function (response) { 
         alert(response.responseText); 
        }, 
        failure: function (response) { 
         alert(response.responseText); 
        } 
       }); 
      }, 
      select: function (e, i) { 

      }, 
      minLength: 1 
     }); 
    }); 
+0

谢谢但仍然它不工作它不会去自动完成功能@RKSaini – grnake

+0

它给我s.nodeName是未定义的错误 – grnake

+0

你仍然在ajax中使用$(this).next('。AttachPId').val()吗? –