disable enter key until user inputs a character?
how would you disable the usage of the enter key on a text area until a character is ent开发者_C百科ered?
this is for a form i'm building - purely for aesthetic reasons :-)
a bit like the facebook news feed page where you can't press enter until entering a single character?
many thanks in advance!
Using jQuery:
$("textarea").live("keydown", function(e){
if(e.which === 13 && $(this).val() === "")
e.preventDefault();
});
Note that if your goal is to avoid any new line characters at the top of a textarea, this won't prevent someone from pasting in new lines.
You would need to add an event handler to listen and trap the return key conditionally. This should point you in the right direction
http://www.webcheatsheet.com/javascript/disable_enter_key.php
精彩评论