【问题标题】:How to call a JS function, on data selection in <input type="text"> from AUTOCOMPLETE list?如何调用 JS 函数,从 AUTOCOMPLETE 列表中选择 <input type="text"> 中的数据?
【发布时间】:2012-01-12 11:04:55
【问题描述】:

我有一个带有文本框的表单: 通过键入更改值的任何位置,通过 KeyPress 事件显示警报消息,但如果在 IE 中启用“使用自动完成表单”,然后每当用户双击并从“可能条目,用户之前键入过”列表中选择文本时,它就不起作用”。

【问题讨论】:

    标签: javascript asp.net devexpress


    【解决方案1】:

    为此目的使用客户端“onpropertychange”事件:

    这是标准和 DevExpress(看起来你正在使用它)文本框的解决方案:

    <script type="text/javascript" src="jquery-1.7.1.min.js"></script>
    <script type="text/javascript">
        //DevExpress ASPxTextBox
        function OnInit(s, e) {
            var inputElement = s.GetInputElement();
            ASPxClientUtils.AttachEventToElement(inputElement, "propertychange", function (event) {
                if (event.propertyName === "value") {
                    alert("Value Changed");
                    alert(event.srcElement.value);
                }
            });
        }
    
        //Standard Input
        $(document).ready(function () {
            var inputElement = document.getElementById("txt");
            //var inputElement = document.getElementById('<%=txt.ClientID%>');
            inputElement.attachEvent("onpropertychange", function (event) {
                if (event.propertyName === "value") {
                    alert("Value Changed");
                    alert(event.srcElement.value);
                }
            });
        });
    </script>
    
    <dx:ASPxTextBox ID="txtDX" runat="server" Width="170px">
        <ClientSideEvents Init="OnInit" />
    </dx:ASPxTextBox>
    <br />
    <input id="txt" type="text" runat="server" />
    <br />
    <asp:Button ID="btn" runat="server" Text="Button" />
    

    【讨论】:

      【解决方案2】:

      你想要这样的东西。见
      http://jqueryui.com/demos/autocomplete/

      【讨论】:

      • 嘿,我不想自动完成,我只想在用户从浏览器显示的列表中选择值时处理一个事件。
      【解决方案3】:
      猜你喜欢
      • 1970-01-01
      • 2016-12-06
      • 2016-09-05
      • 1970-01-01
      • 2019-06-03
      • 2021-12-23
      • 2022-11-06
      • 2015-11-14
      • 1970-01-01
      相关资源
      最近更新 更多