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

相关推荐
不秃头的帅哥17 小时前
程序地址空间(基于c++和linxu的一些个人笔记
linux·开发语言·c++·操作系统·内存空间
Dxxyyyy17 小时前
零基础学JAVA--Day41(IO文件流+IO流原理+InputStream+OutputStream)
java·开发语言·python
Dragon Wu17 小时前
ReactNative Expo 使用总结(基础)
javascript·react native·react.js
独自破碎E17 小时前
力场重叠问题
java·开发语言·算法
jiuweiC17 小时前
python 虚拟环境-windows
开发语言·windows·python
前端世界17 小时前
C 语言项目实践:用指针实现一个“班级成绩智能分析器”
c语言·开发语言
真上帝的左手17 小时前
24. 前端-js框架-Electron
前端·javascript·electron
非情剑17 小时前
Java-Executor线程池配置-案例2
android·java·开发语言
毛发浓密的女猴子17 小时前
Git Pull 策略完全指南:Merge、Rebase、Fast-forward 深度对比
前端
夏小花花17 小时前
<editor> 组件设置样式不生效问题
java·前端·vue.js·xss