<!-- HTML Console Example -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML Console</title>
</head>
<body>
    <h1>Using the Console in HTML</h1>
    <p>This example demonstrates how to use the console to log messages from JavaScript.</p>
    <script>
        // Logging a simple message to the console
        console.log("This is a log message from the HTML page.");
        // Logging a warning message
        console.warn("This is a warning message.");
        // Logging an error message
        console.error("This is an error message.");
        // Logging an object to the console
        const person = { name: "Alice", age: 25 };
        console.log("Person object:", person);
        // Using console.table to display data in tabular form
        const data = [
            { id: 1, name: "Alice", age: 25 },
            { id: 2, name: "Bob", age: 30 },
            { id: 3, name: "Charlie", age: 35 }
        ];
        console.table(data);
    </script>
</body>
</html>console.log(): 用于在控制台输出信息,通常用于调试代码。console.warn(): 用于输出警告信息,通常表示潜在的问题。console.error(): 用于输出错误信息,通常表示程序中的错误。console.log(object): 可以输出对象或变量的内容,方便查看复杂数据结构。console.table(): 用于以表格形式展示数组或对象的数据,便于查看和理解。以上代码展示了如何在HTML页面中使用JavaScript的console对象来记录不同类型的消息。
上一篇:图片生成html
下一篇:html 单选
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站