2011-06-12 36 views
1

我現在創建一個Facebook應用程序,需要創建一個評論系統。我已經充分利用了它,但是我還沒有做出的唯一事情就是textarea發送進度。關於輸入做些什麼(如在Facebook的評論)

我想讓它像Facebook一樣在Facebook上使用評論系統。

所以,當用戶點擊輸入,然後會發生ajax請求,但如果用戶按shift + enter,用戶會在沒有任何ajax請求的情況下創建換行符到我的服務器。

回答

1

試試這個:

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

相應的文檔是在這裏:http://api.jquery.com/keypress/

編輯:根據this question,以下是更好:

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

完美,感謝羅曼! :-) – 2011-06-12 16:09:09