Add new line character to textarea instead of submitting form

后端 未结 7 1929
臣服心动
臣服心动 2021-01-04 04:40

I have a form with a text area and hitting the enter key submits my form. How can I make it to add a new line character instead of a form submit.

7条回答
  •  不知归路
    2021-01-04 04:59

    $(document).ready(function(){
    $("#text").keypress(function(event) {   
       if (event.which == 13) { 
          var s = $(this).val();
          $(this).val(s+"\n");  //\t for tab
       }
    });      
    });
    

    This can be done by jquery code that I have given above. Must notice that the use of ready function is necessary when you write above script before the codes of the HTML input field, and not necessary when you write it after the input field codes.If it not working try to use \t in place of \n it will work.

提交回复
热议问题