html dom console.error() 方法用于将错误消息写入控制台。此方法非常适用于测试和调试。
console.error() 方法的语法如下:
console.error(console.error(message))
在这里,message是一个JavaScript字符串或对象。它是一个必需的参数值。
让我们看一个关于HTML DOM console.error()方法的示例 −
<!DOCTYPE html>
<html>
<body>
<h1>console.error() Method</h1>
<p>Click the below button to write object as error message on the console</p>
<button type="button" onclick="errMessage()">ERROR</button>
<script>
function errMessage(){
var errObj = { Message:"ERROR has been caused",Value:"NEGATIVE"};
console.error(errObj);
}
</script>
<p>Press F12 key to view the error message in the console </p>
</body>
</html>这将产生以下输出 −
立即学习“前端免费学习笔记(深入)”;

点击ERROR按钮并查看开发者工具中的控制台选项卡 −

在上面的示例中 −
我们首先创建了一个名为ERROR的按钮,当用户点击时将执行errMessage()函数 −
<button type="button" onclick="errMessage()">ERROR</button>
errMessage()方法创建一个具有成员Message和Value及其各自值的对象。然后将此对象作为参数传递给控制台对象的error()方法。控制台的console.error()方法将对象作为错误消息打印到控制台中 −
function errMessage(){
var errObj = { Message:"ERROR has been caused",Value:"NEGATIVE"};
console.error(errObj);
}以上就是HTML DOM console.error() 方法的详细内容,更多请关注php中文网其它相关文章!
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号