1
$("#text").on("focus", function(){
    $(this).keypress(function(e){                   
        if(e.keyCode == 13 | e.which == 13){
            //this.value += '</p><p>';
            document.execCommand('formatBlock', false, 'p');
        }                   
    });
});

1 Resposta 1

1

Basicamente só é necessário validar quando for digitado Tab     e adicionar uma tabulação (\t).

$(document).delegate('#textarea', 'keydown', function(e) {
  var keyCode = e.keyCode || e.which;

  if (keyCode == 9) {
    e.preventDefault();
    var start = this.selectionStart;
    var end = this.selectionEnd;

    $(this).val($(this).val().substring(0, start) + "\t" +
    $(this).val().substring(end));

    this.selectionStart =
    this.selectionEnd = start + 1;
  }
});
#textarea {
  width: 500px;
  height: 200px
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="textarea"></textarea>

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .