更新时间:2023-11-30 23:24:58
$('textarea')。keypress(function(event){
pre>
if(event.which == 13){
event.preventDefault();
var s = $(this) .val();
$(this).val(s +\ n);
}
});
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.
$('textarea').keypress(function(event) { if (event.which == 13) { event.preventDefault(); var s = $(this).val(); $(this).val(s+"\n"); } });