什么是JavaScript中的onerror()方法?
该的onerror事件处理程序是第一特征,以方便在JavaScript错误处理。只要页面上发生异常,就会在窗口对象上触发error事件。
示例
您可以尝试运行以下代码以onerror()在JavaScript中实现方法-
<html>
<head>
<script>
<!--
window.onerror = function () {
alert("发生错误。");
}
//-->
</script>
</head>
<body>
<p>Click the following to see the result:</p>
<form>
<input type = "button" value = "Click Me" onclick = "myFunc();" />
</form>
</body>
</html>