【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()它们会跳过页面渲染先被执行。

相关推荐
andyweike3 小时前
php笔记
开发语言·笔记·php
Circ.4 小时前
Python 调试 Litellm 本地大模型接口:模型列表与对话接口实操踩坑记录
开发语言·python
Csvn5 小时前
并发模式:让渲染学会排队、插队和让路
前端
可乐鸡翅yeah_5 小时前
新手梳理:M3U8 线上问题,哪些是前端锅,哪些是后端锅
前端·ios·音视频·实时音视频·m3u8·音视频在线播放
Flynt5 小时前
Linear 用 1000 个 PR 换掉 styled-components,我写了 200 个按钮,把这笔账复现了一遍
前端·css·preact
现任明教教主~6 小时前
Thinkphp站群蜘蛛池SaaS系统YanyvSEO含多用户/积分/六大引擎计费/易支付对接
java·开发语言·spring
JavaGuide6 小时前
NVIDIA 又开源了!这次给 AI Agent 加上权限管控
前端·后端
excel6 小时前
prisma 如何处理数据库竞态
前端·数据库·后端
Zhou1411366 小时前
SpringSecurity_02_授权与高级功能
开发语言·python
码匠许师傅7 小时前
【C++三方组件】cpp-httplib:一个头文件起 HTTP 服务
开发语言·c++·http