disable enter key on specific textboxes

前端 未结 9 779
北荒
北荒 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:22

    I found this combine solution at http://www.askmkhize.me/how-can-i-disable-the-enter-key-on-my-textarea.html

    $('textarea').keypress(function(event) {
    
    if ((event.keyCode || event.which) == 13) {
    
        event.preventDefault();
        return false;
    
      }
    
    });
    
    $('textarea').keyup(function() {
    
        var keyed = $(this).val().replace(/\n/g, '
    '); $(this).html(keyed); });

提交回复
热议问题