【问题标题】:Textbox's Textchanged event not fire in chrome文本框的 Textchanged 事件不会在 chrome 中触发
【发布时间】:2015-07-26 00:34:34
【问题描述】:

我正在创建一个搜索所有客户详细信息的页面... 我也在使用 json 来自动完成文本框,其中包含数据表的数据...

<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 设置看起来像..`

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

那个 textchenged 事件在 mozilla 中正确触发,但在 chrome 中不起作用,, 任何人都可以提出一些解决方案....

【问题讨论】:

  • 你为什么使用 AutoPostBack="True" ?
  • AutoPostBack="True" 用于触发任何服务器控件的事件
  • 删除 AutoPostBack="True" 如果你不使用,然后在 chrome 上尝试。
  • 如果我删除了 mozilla 不支持 textchanged 事件
  • 请尝试我会工作的。

标签: javascript c# asp.net google-chrome


【解决方案1】:

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

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

并在我们从客户端触发该文本框时删除该文本框的自动回发属性。

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

【讨论】:

    【解决方案2】:
    `  $(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"); }
            });
        }
    

    并从 TextBox 中删除 Autopostback="true"
    `

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多