disable enter key on specific textboxes

前端 未结 9 820
北荒
北荒 2020-12-30 18:25

I was looking for a way to do this, got a few scripts, but none of them is working for me.

When I hit enter in my textboxes, it shouldn\'t do anything.

I hav

9条回答
  •  轮回少年
    2020-12-30 19:29

    Use global selector $('input')...if you use multiple text boxes on page the ID ('#comment') will cause problems. And when using dynamic content bind it using .live e.g.

    $('input:not(textarea)').live('keypress',function(e) {
        if (e.which == 13) return false;
        if (e.which == 13) e.preventDefault();
    });
    

    (Disable enter for text boxes and leaves enter enabled for text areas)

提交回复
热议问题