首页| 新闻| 娱乐| 游戏| 科普| 文学| 编程| 系统| 数据库| 建站| 学院| 产品| 网管| 维修| 办公| 热点
这个东西是在线写 js 脚本的时候,用来即时查错的东西!
也就是,当发现所编写的脚本有问题的时候会有相应的提示,并且在源代码框中高亮标示出错行,方便除错
<html><head><title>debug textarea</title><meta http-equiv='content-type' content='text/html; charset=gb2312'></head><style>* { font-size: 12px}body { margin: 10px; padding: 0px}table.list{ cursor: default; border:1px solid #cccccc background-color: #cccccc; border-collapse: collapse; border-color: #cccccc;}</style><script language="javascript">// coded by windy_sk <windy_sk@126.com> 20040205
function reporterror(msg,url,line) { var str = "you have found an error as below: /n/n"; str = "err: " msg " on line: " line; alert(str); return true;}
window.onerror = reporterror;
document.onkeydown = function() { if(event.ctrlkey){ switch(event.keycode) { case 82: //r runcode(); break; case 83: //s savecode(); break; case 71: //g goto(prompt('please input the line number', '1')); break; case 65: //a document.execcommand("selectall"); break; case 67: //c document.execcommand("copy"); break; case 88: //x document.execcommand("cut"); break; case 86: //v document.execcommand("paste"); break; case 90: //z document.execcommand("undo"); break; case 89: //y document.execcommand("redo"); break; default: break; } event.keycode = 0; event.returnvalue = false; } return;}
function show_ln(){ var txt_ln = document.getelementbyid('txt_ln'); var txt_main = document.getelementbyid('txt_main'); txt_ln.scrolltop = txt_main.scrolltop; while(txt_ln.scrolltop != txt_main.scrolltop) { txt_ln.value = (i ) '/n'; txt_ln.scrolltop = txt_main.scrolltop; } return;}
function edittab(){ var code, sel, tmp, r; 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); if(sel.parentelement() != tmp.parentelement()) return;; 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); if(sel.parentelement() != tmp.parentelement()) return; 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); if(sel.parentelement() != tmp.parentelement()) return; tmp.setendpoint('endtoend', sel); sel.text = '/r/n' tmp.text.replace(tmp.text.replace(/^[/t ] /g, ""),""); sel.select(); break; default : event.returnvalue = true; break; } return;}
function runcode() { var str = document.getelementbyid("txt_main").value; var code_win = window.open('about:blank'); code_win.document.open(); code_win.document.writeln("<script>"); code_win.document.writeln("function reporterror(msg,url,line){/nline-=14;/nvar str='you have found an error as below: //n//n';/nstr ='err: ' msg ' on line: ' (line);/nalert(str);/nopener.goto(line);/nopener.focus();/nwindow.onerror=null;/nsettimeout('self.close()',10);/nreturn true;/n}"); code_win.document.writeln("window.onerror = reporterror;"); code_win.document.writeln("<//script>"); code_win.document.writeln(str); code_win.document.close(); return;}
function savecode() { var str = document.getelementbyid("txt_main").value; var code_win = window.open('about:blank','_blank','top=10000'); code_win.document.open(); code_win.document.writeln(str); code_win.document.close(); code_win.document.execcommand('saveas','','code.html'); code_win.close(); return;}
function goto(ln) { if(!/^/d $/.test(ln) || ln==0) return; var obj = document.getelementbyid("txt_main"); var rng = obj.createtextrange(); var arr = obj.value.split(//n/); if(ln>arr.length) ln = arr.length; var str_tmp = ""; for(var i=0; i<ln-1; i ) { str_tmp = arr[i]; } rng.movestart('character',str_tmp.length); str_tmp = ""; for(i=ln; i<arr.length; i ) { str_tmp = arr[i]; } rng.moveend('character',-str_tmp.length); rng.select(); return;}
window. {document.getelementbyid("txt_main").value = "<script>/nalert(')/n<//script>";}</script><body><table width='600' class='list' border='1' bgcolor='#eeeeee' bordercolorlight='#000000' bordercolordark='#ffffff' cellpadding='0' cellspacing='0'> <tr bgcolor='#cccccc'> <td colspan='2' height='20' align='center'><b>debug textarea</b></td> </tr> <tr> <td colspan='2'> <table width='95%' border='0' align='center' >||| <tr> <td align='center'><br /> <textarea id='txt_ln' name='content' rows='10' style='width:40px;overflow:hidden;height:200px;border-right:0px;text-align:right;line-height:14px' onselectstart='this.nextsibling.focus();return false' readonly></textarea><textarea id='txt_main' name='content' rows='10' cols='80' onkeydown='edittab()' onkeyup='show_ln()' onscroll='show_ln()' wrap='off' style='overflow:auto;height:200px;padding-left:5px;border-left:0px;line-height:14px'></textarea> <script>for(var i=1; i<=20; i ) document.getelementbyid('txt_ln').value = i '/n';</script> </td> </tr> <tr> <td align='center'><br /> <input type='button' value=' 运 行 ' onclick='runcode()' accesskey='r'> <input type='button' value=' 保 存 ' onclick='savecode()' accesskey='s'> <input type='button' value=' 跳 转 ' onclick="goto(prompt('please input the line number', '1'))" accesskey='g'> </td> </tr> </table> </td> </tr></table></body></html>
练就火眼金睛 十一种常见电脑
打印机共享提示“操作无法完成
如何查找有故障的配件
回眸一笑百魅生,六宫粉黛无颜色
岁月静美,剪一影烟雨江南
芜湖有个“松鼠小镇”
小满:小得盈满,一切刚刚好!
一串串晶莹剔透的葡萄,像一颗颗宝石挂在藤
正宗老北京脆皮烤鸭
人逢知己千杯少,喝酒搞笑图集
搞笑试卷,学生恶搞答题
新闻热点
疑难解答
图片精选
Dreamweaver问题集锦大全
Dreamweaver CS3 的最新功能
Dreamweaver CS3代码片断功能面板
Dreamweaver技巧:运用代码片断工具
网友关注