The problem that occurs in your code is that the function which
not supported in older versions of Internet Explorer, only from version 9 of it.
So to solve your problem, with a simple solution and cross browser capture of the enter key, you can do as follows below:
$(document).keypress(function(e){
var keycode = e.keyCode ? e.keyCode : e.which;
if(keycode === 13){
$('.button_ok').click();
}
});
$(document).keypress(function(e){
var keycode = e.keyCode ? e.keyCode : e.which;
if(keycode === 13){
$('.button_ok').click();
}
});
$('.button_ok').click(function() {
alert('OK!');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input type="text" name="txt_input" />
<input type="button" class="button_ok" value="OK" />
$(window).keypress(function(e){
var keycode = e.keyCode ? e.keyCode : e.which;
if(keycode === 13){
$('.button_ok').click();
}
});
$('.button_ok').click(function() {
alert('OK!');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input type="button" class="button_ok" value="OK" />
This question has two votes to close as not clear enough. To me, it seemed to be quite clear, so I voted to keep it open. Someone who has voted or will vote for closure, I would like to speak out to explain what is wrong?
– Victor Stafusa
When checking the IE Console tab (F12), does the browser report an error after you type something? If yes, post your question together.
– Joao Paulo
I believe it is necessary to complement the post by saying which version of jQuery is being used.
– Bacco