当前位置:软件学习 > Dreamweaver >>

用 onerror 获取错误信息

这个东西是在线写 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: nn";
 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
    do

补充:网页制作,Dreamweaver
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,