tab 键

作者: chiupen | 来源:发表于2018-06-03 11:31 被阅读0次
    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 键

          本文链接:https://www.haomeiwen.com/subject/axzdsftx.html