开发者

On enter do something (Like on facebook comments)

开发者 https://www.devze.com 2023-03-12 02:56 出处:网络
I\'m creating a facebook application at the moment and need to create a comment system. I\'ve made the most of it, but the only thing i not have made yet is the textarea sending progress.开发者_开发知

I'm creating a facebook application at the moment and need to create a comment system. I've made the most of it, but the only thing i not have made yet is the textarea sending progress.开发者_开发知识库

I want to make it like facebook have done it with the comment system on facebook.

So when a user clicks enter, then a ajax request happens, but if a user press shift+enter, the user makes a linebreak without any ajax request to my server.


Try this :

$('#target').keypress(function(event) {
  if (event.which == '13' && !event.shiftKey) {
     // Yout ajax request here
   }
});

The corresponding doc is here : http://api.jquery.com/keypress/

EDIT : According to this question, the following is better :

$('#target').keypress(function(event) {
    if (((event.keyCode || event.which) == 13) && !event.shiftKey) {
        // Yout ajax request here
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消