简体   繁体   English

ASP.NET:未触发 onchange 事件

[英]ASP.NET : onchange Event not triggered

I have an asp.net program in which I place a marker on a google map when the address in a textbox is changed.我有一个 asp.net 程序,当文本框中的地址更改时,我会在其中放置一个标记在谷歌地图上。 This Javascript is triggered by the onchange event.这个 Javascript 是由onchange事件触发的。 However I have noticed that if the user does not 'tab' out of the box before clicking submit, the event does not fire.但是我注意到如果用户在点击提交之前没有“标签”开箱即用,则该事件不会触发。 Is there a way I can fix this?有没有办法解决这个问题?

I think what you are trying to achieve is impossible.我认为你想要达到的目标是不可能的。 the onchange event, happens only when you lose focus on the element. onchange 事件仅在您失去对元素的关注时发生。 You could use onkeypress, onkeydown or onkeyup to get that change quicker.您可以使用 onkeypress、onkeydown 或 onkeyup 来更快地进行更改。 The problem here is that the value of the textbox is going to be changed by the click of an external element and therefore, you cannot bind it directly to the textbox.这里的问题是文本框的值将通过单击外部元素而改变,因此,您不能将其直接绑定到文本框。

If you know exactly what the clickable elements would be, you could add a click event to each one of them, pointing to a function that would test the textbox current value against the latest known value and if they were different, do whatever you want to do.如果您确切地知道可点击元素是什么,您可以为每个元素添加一个点击事件,指向一个函数,该函数将根据最新的已知值测试文本框当前值,如果它们不同,请执行您想要的任何操作做。 But i don't think that's the case...但我不认为是这样...

following your comment, you should add a submit event to the form, that would compare the current state of the textbox before submitting the form...根据您的评论,您应该向表单添加一个提交事件,该事件将在提交表单之前比较文本框的当前状态...

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

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