简体   繁体   English

如何在数据选择中调用JS函数 <input type=“text”> 从自动完成列表中?

[英]How to call a JS function, on data selection in <input type=“text”> from AUTOCOMPLETE list?

我有一个带有文本框的表单:通过键入更改值,并通过KeyPress事件显示警报消息,但是如果在IE中启用了“对表单使用自动完成”功能,则每当用户双击并从列表中选择文本时,该功能均不起作用“可能的条目,用户已经输入过”。

Use the client-side “ onpropertychange ” event for this purpose: 为此,请使用客户端“ onpropertychange ”事件:

Here is the solution for both the standard and DevExpress (it looks like you are using it) textboxes: 这是标准和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" />

U want some thing like this.see 你想要这样的东西。见
http://jqueryui.com/demos/autocomplete/ http://jqueryui.com/demos/autocomplete/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM