Diferenças entre edições de "Adding an "onenter" event to an input element"
Saltar para a navegação
Saltar para a pesquisa
(Criou a página com "Input elements in Javascript do not really have an "onenter" event. You can, however, simulate such an event by hooking the "onkeypress" event: <syntaxhighlight lang="javas...") |
|||
Linha 1: | Linha 1: | ||
Input elements in Javascript do not really have an "onenter" event. You can, however, simulate such an event by hooking the "onkeypress" event: | Input elements in Javascript do not really have an "onenter" event. You can, however, simulate such an event by hooking the "onkeypress" event: | ||
− | < | + | <code lang="javascript"> |
var l_input = document.getElementById("myelement"); | var l_input = document.getElementById("myelement"); | ||
l_input.onkeypress = function(p_event) { if(13 == p_event.keyCode) this.submit(); } | l_input.onkeypress = function(p_event) { if(13 == p_event.keyCode) this.submit(); } | ||
− | </ | + | </code> |
That's it. As simple as that. | That's it. As simple as that. |
Revisão das 16h20min de 1 de junho de 2018
Input elements in Javascript do not really have an "onenter" event. You can, however, simulate such an event by hooking the "onkeypress" event:
var l_input = document.getElementById("myelement");
l_input.onkeypress = function(p_event) { if(13 == p_event.keyCode) this.submit(); }
That's it. As simple as that.