HTML DOM console.info() 方法

htmlweb developmentfront end technology更新于 2024/6/1 20:28:17

HTML DOM console.info() 方法用于向控制台输出信息性消息。此方法可用于调试和测试。某些浏览器(例如 Firefox、Chrome)会为使用此方法打印的语句显示一个蓝色的小 i 图标。

语法

以下是 HTML DOM console.info() 方法的语法 −

console.info( message )

此处,消息是必需参数,可以是字符串或对象类型。它显示在控制台中。

示例

让我们看一个 HTML DOM console.info() 方法的示例 −

<!DOCTYPE html>
<html>
<body>
<h1>console.info() Method</h1>
<p>Press F12 key to view the message in the console view.</p>
<button onclick="printInfo()">INFO</button>
<script>
   function printInfo(){
      console.info("Information is printed");
      console.info("This is some other information ");
   }
</script>
</body>
</html>

输出

这将产生以下输出 −

点击 INFO 按钮并查看控制台视图 −

在上面的例子中 −

我们创建了一个按钮 INFO,当用户点击该按钮时,它将执行 printInfo() 函数 −

<button onclick="printInfo()">INFO</button>

printInfo() 方法内部包含 console.info() 方法,用于将信息消息打印到控制台。从输出中可以看到,使用 console.info() 写入的消息旁边有一个 i 图标 −

function printInfo(){
   console.info("Information is printed");
   console.info("This is some other information ");
}

相关文章


有用资源