How to detect a textbox's content has changed

后端 未结 15 2122
猫巷女王i
猫巷女王i 2020-11-22 16:10

I want to detect whenever a textbox\'s content has changed. I can use the keyup method, but that will also detect keystrokes which do not generate letters, like the arrow ke

15条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 16:21

    This Code detects whenever a textbox's content has changed by the user and modified by Javascript code.

    var $myText = jQuery("#textbox");
    
    $myText.data("value", $myText.val());
    
    setInterval(function() {
        var data = $myText.data("value"),
        val = $myText.val();
    
        if (data !== val) {
            console.log("changed");
            $myText.data("value", val);
        }
    }, 100);
    

提交回复
热议问题