admin管理员组文章数量:1410674
The following code will submit an ajax form when the user hits ctrl+enter while in the feedback input area. It works fine - but only once. I need to bind this function to the ment form so it persists and allows multiple submissions. In other words - the form is cleared and represented to the user after each submission. However, the following code only works for the first submission and thus ctrl+enter doesn't work for the second submission.
$('#ment_body').keydown(function(e) {
if (e.ctrlKey && e.keyCode === 13) {
return $('#ment_submit').trigger('submit');
}
});
I've tried .live and .bind but can't get the syntax right to allow resubmission.
Thanks
The following code will submit an ajax form when the user hits ctrl+enter while in the feedback input area. It works fine - but only once. I need to bind this function to the ment form so it persists and allows multiple submissions. In other words - the form is cleared and represented to the user after each submission. However, the following code only works for the first submission and thus ctrl+enter doesn't work for the second submission.
$('#ment_body').keydown(function(e) {
if (e.ctrlKey && e.keyCode === 13) {
return $('#ment_submit').trigger('submit');
}
});
I've tried .live and .bind but can't get the syntax right to allow resubmission.
Thanks
Share Improve this question edited Jul 29, 2011 at 18:16 glimpse nirvana asked Jul 28, 2011 at 19:52 glimpse nirvanaglimpse nirvana 3213 silver badges8 bronze badges 3- for me it works as many times as i want – Emil Condrea Commented Jul 28, 2011 at 20:00
- what does your submit event handler look like – Evan Commented Jul 28, 2011 at 20:02
- If you found the solution, could you move your answer in an answer and mark it as resolved ? – Julien Roncaglia Commented Jul 28, 2011 at 22:11
2 Answers
Reset to default 6This does it. I need .live to get it to persist for future events. I just got the syntax wrong multiple times.
$('#ment_body').live('keydown', function(e) {
if (e.ctrlKey && e.keyCode === 13) {
$('#ment_submit').trigger('submit');
}
});
you are using an id selector and if it's ments chances are same div's will be created with multiple id's and that could be the reason that it gets executed only once.
本文标签: javascriptHow to use jquery to bind ctrlenter to ajax form submissionStack Overflow
版权声明:本文标题:javascript - How to use jquery to bind ctrl+enter to ajax form submission - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745065235a2640481.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论