<div class="htmlarea"><textarea id="runcode55494"> <script> 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(/\r\n/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(/\r\n/g, "\r\t") code = code.replace(/\r\n/g, "\r\t") 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<tmp.text.match(/^[\t]+/g)[0].length; i++) tabs += "\t" sel.text = "\r\n"+tabs sel.select() break default : event.returnValue = true break } } </script> <textarea rows="24" onkeydown="editTab()" style="width:100%" name="filetext" cols="80"> </textarea><br><input onclick="runEx('runcode55494')" type="button" value="运行代码"> <input onclick="doCopy('runcode55494')" type="button" value="复制代码"> <input onclick="doSave(runcode55494)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</textarea></div>