📜  textarea 中的 js 选项卡 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:32.483000             🧑  作者: Mango

代码示例1
document.querySelector('#textarea').addEventListener('keydown', e => {
    if ( e.key === 'Tab' && !e.shiftKey ) {
        // execCommand operations are "Cmd|Ctrl+Z"-able
          // note: execCommand is deprecated and may not work in the future
        document.execCommand('insertText', false, "\t");
        e.preventDefault();
        return false;
    }
});