用 onerror 获取错误信息
<P>这个东西是在线写 js 脚本的时候,用来即时查错的东西!</P><P>也就是,当发现所编写的脚本有问题的时候会有相应的提示,并且在源代码框中高亮标示出错行,方便除错<BR></P><FIELDSET style="COLOR: #808080" align=center><P><LEGEND align=center></LEGEND><HTML><BR><HEAD><BR><TITLE>Debug Textarea</TITLE><BR><meta http-equiv='Content-Type' content='text/html; charset=gb2312'><BR></HEAD><BR><style><BR>* {<BR> font-size: 12px<BR>}<BR>body {<BR> margin: 10px; padding: 0px<BR>}<BR>table.list{<BR> cursor: default;<BR> border:1px solid #cccccc<BR> background-color: #cccccc;<BR> border-collapse: collapse;<BR> border-Color: #cccccc;<BR>}<BR></style><BR><script language="javascript"><BR>// Coded by windy_sk <windy_sk@126.com> 20040205</P><P>function reportError(msg,url,line) {<BR> var str = "You have found an error as below: \n\n";<BR> str= "Err: " msg " on line: " line;<BR> alert(str);<BR> return true;<BR>}</P><P>window.onerror = reportError;</P><P><BR>document.onkeydown = function() {<BR> if(event.ctrlKey){<BR>switch(event.keyCode) {<BR> case 82: //r<BR> runcode();<BR> break;<BR> case 83: //s<BR> savecode();<BR> break;<BR> case 71: //g<BR> goto(prompt('Please input the line number', '1'));<BR> break;<BR> case 65: //a<BR> document.execCommand("SelectAll");<BR> break;<BR> case 67: //c<BR> document.execCommand("Copy");<BR> break;<BR> case 88: //x<BR> document.execCommand("Cut");<BR> break;<BR> case 86: //v<BR> document.execCommand("Paste");<BR> break;<BR> case 90: //z<BR> document.execCommand("Undo");<BR> break;<BR> case 89: //y<BR> document.execCommand("Redo");<BR> break;<BR> default:<BR> break;<BR>}<BR>event.keyCode = 0;<BR>event.returnValue = false;<BR> }<BR> return;<BR>}</P><P><BR>function show_ln(){<BR> var txt_ln= document.getElementById('txt_ln');<BR> var txt_main= document.getElementById('txt_main');<BR> txt_ln.scrollTop = txt_main.scrollTop;<BR> while(txt_ln.scrollTop != txt_main.scrollTop) {<BR>txt_ln.value= (i) '\n';<BR>txt_ln.scrollTop = txt_main.scrollTop;<BR> }<BR> return;<BR>}</P><P><BR>function editTab(){<BR> var code, sel, tmp, r;<BR> event.returnValue = false;<BR> sel =event.srcElement.document.selection.createRange();<BR> r = event.srcElement.createTextRange();</P><P> switch (event.keyCode){<BR>case (8) :<BR> if (!(sel.getClientRects().length > 1)){<BR> event.returnValue = true;<BR> return;<BR> }<BR> code = sel.text;<BR> tmp = sel.duplicate();<BR> tmp.moveToPoint(r.getBoundingClientRect().left, sel.getClientRects().top);<BR> if(sel.parentElement() != tmp.parentElement()) return;;<BR> sel.setEndPoint('startToStart', tmp);<BR> sel.text = sel.text.replace(/^\t/gm, '');<BR> code = code.replace(/^\t/gm, '').replace(/\r\n/g, '\r');<BR> r.findText(code);<BR> r.select();<BR> break;<BR>case (9) :<BR> if (sel.getClientRects().length > 1){<BR> code = sel.text;<BR> tmp = sel.duplicate();<BR>  
页:
[1]