AngularJS textarea newline on enter key

前端 未结 1 745
逝去的感伤
逝去的感伤 2021-01-16 07:18

I am developing an AngularJS application same like how we post answers and questions on stackoverflow and we get live preview of our answers or question just below the texta

1条回答
  •  悲哀的现实
    2021-01-16 08:06

    Thats because newlines in the textarea are not HTML line breaks. You need to replace them with something like this:

    $(document).ready(function() {
      var pad = $('#pad');
      var board = $('#board');
    
      pad.keypress(function(event) {
        board.html(pad.val().replace(/\r?\n/g, '
    ')); }); });
    
    
    

    0 讨论(0)
提交回复
热议问题