tab 键

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();
        }

你可能感兴趣的:(tab 键)