开发者

How can I get the onChangeEvent _sooner_?

I'm using GWT to monitor changes to a TextArea. When the user types, I catch Key开发者_StackOverflowPressEvents and update my logic accordingly.

However, when the user uses the mouse to change the value of the TextArea (e.g. cut & paste or drag) I do not get KeyPressEvents (of course). I still want to update immediately. I tried ChangeEvents, but it seems that they are only fired much later, when the TextArea loses focus.

I could listen for all ClickEvents, but is there a more logical mechanism that will alert my code right after the text in a textarea changes for any reason?


You could use setTimeout:

var ta = document.getElementById("yourTextarea");
var value = ta.value;

function check() {
    if ( ta.value !== value ) {
        // value has changed
        value = ta.value;
    }
    setTimeout(check, 100);
}

check();


Seems like catching the paste & cut events directly is the best way - there's no "changed-at-all" event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜