Doubts about the keydown event

two input boxes, listen for the keydown event to one of the input boxes, and assign its value to the other box, but the value is always one bit less, so there is no problem with the keyup event

clipboard.png

<div class="test">
    <input class="test1" type="text" name="test1">
    <input class="test2" type="text" name="test2">
</div>
<script type="text/javascript">
    var test1 = document.getElementsByClassName("test1")[0];
    var test2 = document.getElementsByClassName("test2")[0];

    test1.addEventListener("keydown", function(e) {
        test2.value = e.target.value;
    })
</script>
Mar.09,2021
The

keydown event is triggered before the text is typed into the text box. If you output the text in the text box in the keydown event, you will get the text before the keyboard event is triggered. When the keyup event is triggered, the operation of all keyboard events has been completed, and you will get the text after the keyboard event has been triggered. The flow of events that occur in the input box are focus, keydown, input, keyup, change, and blur.
check out other people's articles and post their links Link 1 Link 2


you can try delaying the execution of
setTimeOut (function () {test2.value = e.target.value;}, 0)

until the next round of event cycles.
Menu