var el = document.querySelector('textarea');
el.addEventListener("keydown", function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode === 9) {
var start = el.selectionStart,
end = el.selectionEnd;
el.value = el.value.substring(0, start)
+ "\t"
+ el.value.substring(end);
el.selectionStart = el.selectionEnd = start + 1;
e.preventDefault();
}
网友评论