function editTab() { var code, sel, tmp, r var tabs="" event.returnValue = false sel =event.srcElement.document.selection.createRange() r = event.srcElement.createTextRange() switch (event.keyCode) { case (8) : if (!(sel.getClientRects().length > 1)) { event.returnValue = true return } code = sel.text tmp = sel.duplicate() tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top) sel.setEndPoint("startToStart", tmp) sel.text = sel.text.replace(/^t/gm, "") code = code.replace(/^t/gm, "").replace(/rn/g, "r") r.findText(code) r.select() break case (9) : if (sel.getClientRects().length > 1) { code = sel.text tmp = sel.duplicate() tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top) sel.setEndPoint("startToStart", tmp) sel.text = "t"+sel.text.replace(/rn/g, "rt") code = code.replace(/rn/g, "rt") r.findText(code) r.select() } else { sel.text = "t" sel.select() } break case (13) : tmp = sel.duplicate() tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects()[0].top) tmp.setEndPoint("endToEnd", sel) for (var i=0; tmp.text.match(/^[t]+/g) && i
【在textarea输入Tab】相关文章:
★ TypeError document.getElementById(...) is null错误原因
★ JS排序方法(sort,bubble,select,insert)代码汇总
★ IP地址输入框
★ JavaScript中用toString()方法返回时间为字符串