javascript javascript javascript window.event I have a question.

Asked 1 years ago, Updated 1 years ago, 77 views

window.onload=function() {
            input_2.onkeydown=function() {
                // Extracts event objects.
                variable event=e||window.event; // It will turn around without doing this
                // The user's input is backspace and no characters are entered
                if(event.keyCode==8 && input_2.value.length==0) {
                    input_1.focus();
                }
            };
    }

Hello, the above code is part of the code that automatically focuses on the first digit of the resident number when you press the backspace key when there is no content in the back digit of the resident number.

var event=e||window.event;

Even if you don't do this part, it works well, so I wonder what the meaning of that part is.

javascript event

2022-09-21 18:00

1 Answers

It's an old-fashioned relic. Unless you try to correspond to an older IE, this code is no longer needed.

Rather, erase the corresponding line and write it as follows.

window.onload=function() {
   input_2.onkeydown=function(event) {
        /*...*/
   }
}

Writing window.event is the same code as above. But for a number of reasons, the code above is safer and better for meaningful delivery.


2022-09-21 18:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.