admin管理员组文章数量:1300026
$(function(){
$('.inviteClass').keypress(function() {
if(event.keyCode=='13') {
doPost();
}
});
Here I have one small requirement. Pressing keyboard Enter to submit the form and it is working fine in FireFox and Chrome, as well as IE 7 and 8, but it is not working in IE9 and IE 10.
Please help me.
$(function(){
$('.inviteClass').keypress(function() {
if(event.keyCode=='13') {
doPost();
}
});
Here I have one small requirement. Pressing keyboard Enter to submit the form and it is working fine in FireFox and Chrome, as well as IE 7 and 8, but it is not working in IE9 and IE 10.
Please help me.
Share Improve this question edited Feb 14, 2013 at 6:21 Samuel Liew 79.1k111 gold badges168 silver badges303 bronze badges asked Feb 14, 2013 at 5:36 RajasekharRajasekhar 2,4553 gold badges29 silver badges50 bronze badges 2- In IE, jQuery will fire keydown(), not keypress() for the arrow keys, because they are considered 'special' keys. – sasi Commented Feb 14, 2013 at 5:44
- possible duplicate :stackoverflow./questions/1427912/… and stackoverflow./questions/3546140/… – depz123 Commented Feb 14, 2013 at 5:44
4 Answers
Reset to default 8Points to note:
- You are missing a closing bracket.
- Also, change the selector to
window
- Use
.on()
function - Use the
.which
property of event. See jQuery documentation - The keycode is an integer - remove the quotes
- Add a
return false;
to stop the event from bubbling to the form (and possibly submitting the form twice). See Submitting a form on 'Enter' with jQuery?
Final code:
$(function() {
$(window).on('keydown', function(event) {
if(event.which == 13) {
doPost();
return false;
}
});
});
try
$('.inviteClass').keypress(function (e) {
c = e.which ? e.which : e.keyCode;
if (c == 13) {
doPost();
e.preventDefault();
return false; //<---- Add this line
}
});
you must use jQuery's event.which, also change '13' to 13 (a closing bracket was also missing):
$(function(){
$('.inviteClass').keypress(function(event) {
if(event.which == 13) {
doPost();
}
});
});
Please Try to use keydown event and also pass the event object in the function like this
$(function(){$('.inviteClass').keydown(function(event){if(event.keyCode=='13'){doPost();}});
or
$(function(){$('.inviteClass').keypress(function(event){if(event.keyCode=='13'){doPost();}});
Hope this will help you
Thanks
本文标签: javascriptquotEnterquot Keypress to Submit the Form is not working in IE 910Stack Overflow
版权声明:本文标题:javascript - "Enter" Keypress to Submit the Form is not working in IE 910 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741649535a2390390.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论