I have a form with a text box: wherever value changed by typing, showing alert message by KeyPress event, but it does not work if "Use AutoComplete for Form" is enable in IE and then whenever user double click and select text from a list of "possible entries, user have typed before".
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Use the client-side “onpropertychange” event for this purpose:
Here is the solution for both the standard and DevExpress (it looks like you are using it) textboxes:
<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:
U want some thing like this.see
http://jqueryui.com/demos/autocomplete/
回答3:
Take a look at these links:
http://www.phdesign.com.au/programming/ie-autocomplete-doesnt-fire-onchange-event-handler/
Why does the javascript onchange event not fire if autocomplete is on?