Относительно этого вопроса, попробуйте:
$(function () {
$("textarea").keydown(function (e) {
if (e.keyCode == 9) {
e.preventDefault();
var $this = $(this);
var pos = $this[0].selectionStart;
$this.val($this.val().substring(0, pos) + " " + $this.val().substring(pos));
$this.setCursorPosition(pos + 4);
}
});
});
И добавьте JQuery из этого сообщения.
new function($) {
$.fn.setCursorPosition = function(pos) {
if ($(this).get(0).setSelectionRange) {
$(this).get(0).setSelectionRange(pos, pos);
} else if ($(this).get(0).createTextRange) {
var range = $(this).get(0).createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}
}(jQuery);