Reputation: 57
window.onkeyup = keyup;
var inputTextValue;
function keyup(e) {
inputTextValue = e;
$('#searchValue').text("https://duckduckgo.com/?q=" + inputTextValue);
if (e.keyCode == 13) {
window.location = "https://duckduckgo.com/?q=" + inputTextValue;
}
}
I dont understand this code. Does "window.onkeyup = keyup" mean that window.onkeyup will copy the value of the variable keyup?
What does the parameter e do ? I don't see code that call the function and pass argument to that e parameter
Upvotes: 2
Views: 427
Reputation: 89234
window.onkeyup = keyup;
assigns the keyup function to the onkeyup property of the window. The function is then used as the event handler whenever a keyup event occurs on the window (or bubbles up to it).
The keyup event fires when the user releases a key that was previously pressed.
e
is the event, which is, in this case, a KeyboardEvent
.
According to MDN, for target.onkeyup = functionRef
:
functionRef is a function name or a function expression. The function receives a KeyboardEvent object as its sole argument.
Upvotes: 2
Reputation: 2823
answer:
keyup
function will be called.e
is the even object mainly e
contain the keyboard related value,s example e.keyCode
equal 13
for enter key.so if (e.keyCode == 13)
means when enter key will press and release then that block will be execute.
Upvotes: 1