开发者

disable enter key until user inputs a character?

开发者 https://www.devze.com 2023-02-22 10:28 出处:网络
how would you disable the usage of the enter key on a text area until a character is ent开发者_C百科ered?

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

0

精彩评论

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