tab 键
2018-06-03 本文已影响0人
chiupen
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();
}