try/catch

1.try/catchjavascript

<html>
<head>
<script type="text/javascript">
var txt=""
function message()
{
try
   {
   adddlert("Welcome guest!")
   }
catch(err)
   {
   txt="本頁中存在錯誤。\n\n"
   txt+="錯誤描述:" + err.description + "\n\n"
   txt+="點擊「肯定」繼續。\n\n"
   alert(txt)
   }
}
</script>
</head>html

<body>
<input type="button" value="查看消息" />
</body>java

</html>
 ide

2.帶有確認框的try/catchhtm

<html>
<head>
<script type="text/javascript">
var txt=""
function message()
{
try
   {
   adddlert("Welcome guest!")
   }
catch(err)
   {
     txt="本頁中存在錯誤。\n\n"
     txt+="點擊「肯定」繼續查看本頁,\n"
     txt+="點擊「取消」返回首頁。\n\n"
     if(!confirm(txt))
         {
         document.location.href="/index.html"
         }
   }
}
</script>
</head>ip

<body>
<input type="button" value="查看消息" />
</body>input

</html>
 it

相關文章
相關標籤/搜索