开发者

On enter do something (Like on facebook comments)

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜