2015-05-14 44 views
2

我创建一个网页,搜索所有的客户信息... 我也使用JSON用于与数据表中的数据自动完成文本框...文本框的TextChanged事件中铬不火

<script type="text/javascript"> 
$(document).ready(function() { 
    $("#<%=txtSearch.ClientID %>").autocomplete({ 
     source: function (request, response) { 
      $.ajax({ 
       url: '<%=ResolveUrl("~/Service.asmx/GetCustomers") %>', 
       data: "{ 'prefix': '" + request.term + "'}", 
       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) { 
      $("#<%=hfCustomerId.ClientID %>").val(i.item.val); 
     }, 
     minLength: 1 
    }); 

}); 

我想对TextChanged事件文本框中选定名称的显示数据, 他们textbgox的设置看起来like..`

<asp:TextBox ID="txtSearch" runat="server" AutoPostBack="True" 
     ontextchanged="txtSearch_TextChanged"></asp:TextBox> 

这textchenged事件触发正常在Mozilla,但在Chrome不工作,, 任何人都可以提出一些解决办法....

+0

“真”? –

+0

AutoPostBack =“True”用于触发任何服务器控件的事件 –

+0

删除AutoPostBack =“True”,如果您不使用然后尝试使用chrome。 –

回答

0

从自动完成列表,选择一个值后,我会建议调用服务器端的文本框onchange事件,

... 
select: function (e, i) { 
     $("#<%=hfCustomerId.ClientID %>").val(i.item.val); 
     __doPostBack("txtSearch", "TextChanged"); 
    }, 
    minLength: 1 
}); 

和删除,因为我们是文本框的AutoPostBack属性从客户端发射它。

或者您可以在选择事件上进行ajax调用,并在客户端自己填充所需的数据。

0
` $(document).ready(function() { 
     var prm = Sys.WebForms.PageRequestManager.getInstance(); 
     prm.add_initializeRequest(InitializeRequest); 
     prm.add_endRequest(EndRequest);   
     InitAutoCompl(); 
    }); 

    function InitializeRequest(sender, args) { 
    } 

    function EndRequest(sender, args) {   
     InitAutoCompl(); 
    } 

    function InitAutoCompl() { 
     $("#<%=txtSearch.ClientID %>").autocomplete({ 
      source: function (request, response) { 
       $.ajax({ 
        url: ''<%=ResolveUrl("~/Service.asmx/GetCustomers") %>', 
        data: "{ 'prefix': '" + request.term + "'}", 
        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); 
        } 
       }); 
      }, 

      minLength: 1, change: function (event, ui) { __doPostBack("txtSearch", "TextChanged"); } 
     }); 
    } 

,为什么您使用的AutoPostBack = “真” 删除的AutoPostBack =从文本框
`

相关问题