简体   繁体   English

检测没有事件处理程序的情况下TextBox控件的文本是否已更改

[英]Detect if TextBox control's text has changed without the event handler

I know that there is an event handler TextChanged that fires when a TextBox control's text has been changed but I am wondering if there is another way to detect if a TextBox has had it's value changed? 我知道有一个事件处理程序TextChanged当TextBox控件的文本已更改时会触发,但是我想知道是否还有另一种方法来检测TextBox的值是否已更改?

I read that you can do something like store the initial value of the TextBox in the html tag but there was no detail on how to do that. 我读到您可以执行一些操作,例如将TextBox的初始值存储在html标记中,但是没有有关如何执行此操作的详细信息。 Then apparently you can compare the initial value of the TextBox to it's current value and then run some code. 然后,显然您可以将TextBox的初始值与其当前值进行比较,然后运行一些代码。

This is just a trick. 这只是一个把戏。 You must use the native event. 您必须使用本机事件。

var previousText = "";
setInterval(function(){

    var currentText = GetTextboxValue();

    if(currentText != previousText){

        // Raise the event here using currentText.

        previousText = currentText;
    }

}, 200);

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

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