【JavaScript】输入输出语法

目录

一、输出语法

二、输入语法


一、输出语法

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 输出语法1:输出到页面中
        document.write('<h1>我是第一个标题</h1>')

        // 输出语法2:弹出框
        alert('弹出框的内容')

        // 输出语法3:输出到浏览器控制台
        console.log('控制台打印');
    </script>
</body>
</html>

二、输入语法

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 输入语句
        prompt('请输入你的年龄')
    </script>
</body>
</html>

注意:alert()和prompt()它们会跳过页面渲染先被执行。

相关推荐
崔庆才丨静觅10 小时前
hCaptcha 验证码图像识别 API 对接教程
前端
lly20240610 小时前
Bootstrap 警告框
开发语言
2601_9491465310 小时前
C语言语音通知接口接入教程:如何使用C语言直接调用语音预警API
c语言·开发语言
曹牧10 小时前
Spring Boot:如何测试Java Controller中的POST请求?
java·开发语言
passerby606110 小时前
完成前端时间处理的另一块版图
前端·github·web components
KYGALYX10 小时前
服务异步通信
开发语言·后端·微服务·ruby
掘了10 小时前
「2025 年终总结」在所有失去的人中,我最怀念我自己
前端·后端·年终总结
zmzb010310 小时前
C++课后习题训练记录Day98
开发语言·c++
崔庆才丨静觅11 小时前
实用免费的 Short URL 短链接 API 对接说明
前端
崔庆才丨静觅11 小时前
5分钟快速搭建 AI 平台并用它赚钱!
前端