CINXE.COM
<!DOCTYPE html><html lang="zh" data-theme-enabled="1"><head><script>window.currentUser = null;</script><script>window.shopCurrency = "EUR";</script><script>window.localCurrency = "CNY";</script><script>window.countryCode = "cn";</script><script>window.rateShopTo = {"CNY":7.845204198005871,"EUR":1,"USD":1.078956993853182,"AMD":421.5874435300883};</script><title itemprop="name">现代 JavaScript 教程</title><link href="/pack/styles.100020a0bc7cf13be729.css" rel="stylesheet"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, minimum-scale=1.0"><meta name="apple-mobile-web-app-capable" content="yes"><!-- chrome autotranslate is enabled only for "en" main version--><meta name="google" content="notranslate"><script>if (window.devicePixelRatio > 1) document.cookie = 'pixelRatio=' + window.devicePixelRatio + ';path=/;expires=Tue, 19 Jan 2038 03:14:07 GMT';</script><link href="//fonts.googleapis.com/css?family=Open+Sans:bold,italic,bolditalic" rel="stylesheet"><link rel="apple-touch-icon-precomposed" href="/img/favicon/apple-touch-icon-precomposed.png"><link rel="canonical" href="https://zh.javascript.info/"><meta name="msapplication-TileColor" content="#222A2C"><meta name="msapplication-TileImage" content="/img/favicon/tileicon.png"><link rel="icon" href="/img/favicon/favicon.png"><meta itemprop="image" content="https://zh.javascript.info/img/site_preview_en_512x512.png"><meta property="og:title" content="现代 JavaScript 教程"><meta property="og:image" content="https://zh.javascript.info/img/site_preview_en_1200x630.png"><meta property="og:image:type" content="image/png"><meta property="og:image:width" content="1200"><meta property="og:image:height" content="630"><meta property="fb:admins" content="100001562528165"><meta name="twitter:card" content="summary"><meta name="twitter:title" content="现代 JavaScript 教程"><meta name="twitter:site" content="@iliakan"><meta name="twitter:creator" content="@iliakan"><meta name="twitter:image" content="https://zh.javascript.info/img/site_preview_en_512x512.png"><meta name="google-adsense-account" content="ca-pub-6204518652652613"><script data-collect-dnt="true" async src="https://scripts.simpleanalyticscdn.com/latest.js"></script><script>window.GA_ID = "UA-2056213-15";</script><script>window.YANDEX_METRIKA_ID = 65598091;</script><script>{function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),gtag("config","G-2LWB61WGYJ")}</script> <script async src="https://www.googletagmanager.com/gtag/js?id=G-2LWB61WGYJ"></script><script>window.metrika={reachGoal:function(){}},window.yandex_metrika_callbacks=[function(){try{window.metrika=new Ya.Metrika({id:YANDEX_METRIKA_ID,webvisor:!0,clickmap:!0,params:{user:window.currentUser&&window.currentUser.id}}),metrika.trackLinks({delay:150}),window.addEventListener("error",function(r){window.metrika.reachGoal("JSERROR",{src:(r.filename||r.errorUrl)+": "+(r.lineno||r.errorLine),stack:r.stack||r.error&&r.error.stack,message:r.message})})}catch(r){}}];</script><script src="//mc.yandex.ru/metrika/watch.js" async></script><script>window.RECAPTCHA_ID = "6LfmLAEVAAAAAJMykMnf7aY8nkyTRmYi2ynx51R1";</script><script src="/pack/init.352adc9f96be3655bb0a.js"></script><script src="/pack/head.2409f777a10dd3da24b7.js" defer></script><script src="/pack/tutorial.ad3cd9b17d623797fa41.js" defer></script><script src="/pack/frontpage.07e03b47eecfe51e3eba.js" defer></script><link href="/pack/frontpage.334742fced5999da25f0.css" rel="stylesheet"><meta name="description" content="现代 JavaScript 教程:有关示例和任务的简单但详细的解释包括:闭包、文档和事件,以及面向对象编程等。"><script src="/pack/footer.67a36ba7fd7c9d83f0bb.js" defer></script></head><body class="no-icons"><script>window.fontTest();</script><div class="page-wrapper"><!--[if IE]><div style="color:red;text-align:center">很抱歉,我们不支持 Internet Explorer 等浏览器,请使用一个更新版本的浏览器。</div><![endif]--><div class="sitetoolbar"><div class="sitetoolbar__content"><div class="sitetoolbar__lang-switcher"><button class="sitetoolbar__dropdown-button" data-dropdown-toggler>ZH</button><div class="sitetoolbar__dropdown-wrap"><div class="sitetoolbar__dropdown-body"><div class="sitetoolbar__lang-switcher-body"><div class="supported-langs supported-langs_toolbar"><div class="supported-langs__container"><ul class="supported-langs__list" style="height:200px"><li class="supported-langs__item"><a class="supported-langs__link" href="https://ar.javascript.info/"><span class="supported-langs__brief">AR</span><span class="supported-langs__title">عربي</span></a></li><li class="supported-langs__item"><a class="supported-langs__link" href="https://javascript.info/"><span class="supported-langs__brief">EN</span><span class="supported-langs__title">English</span></a></li><li class="supported-langs__item"><a class="supported-langs__link" href="https://es.javascript.info/"><span class="supported-langs__brief">ES</span><span class="supported-langs__title">Español</span></a></li><li class="supported-langs__item"><a class="supported-langs__link" href="https://fa.javascript.info/"><span class="supported-langs__brief">FA</span><span class="supported-langs__title">فارسی</span></a></li><li class="supported-langs__item"><a class="supported-langs__link" href="https://fr.javascript.info/"><span class="supported-langs__brief">FR</span><span class="supported-langs__title">Français</span></a></li><li class="supported-langs__item"><a class="supported-langs__link" href="https://id.javascript.info/"><span class="supported-langs__brief">ID</span><span class="supported-langs__title">Indonesia</span></a></li></ul><ul class="supported-langs__list" style="height:200px"><li class="supported-langs__item"><a class="supported-langs__link" href="https://it.javascript.info/"><span class="supported-langs__brief">IT</span><span class="supported-langs__title">Italiano</span></a></li><li class="supported-langs__item"><a class="supported-langs__link" href="https://ja.javascript.info/"><span class="supported-langs__brief">JA</span><span class="supported-langs__title">日本語</span></a></li><li class="supported-langs__item"><a class="supported-langs__link" href="https://ko.javascript.info/"><span class="supported-langs__brief">KO</span><span class="supported-langs__title">한국어</span></a></li><li class="supported-langs__item"><a class="supported-langs__link" href="https://learn.javascript.ru/"><span class="supported-langs__brief">RU</span><span class="supported-langs__title">Русский</span></a></li><li class="supported-langs__item"><a class="supported-langs__link" href="https://tr.javascript.info/"><span class="supported-langs__brief">TR</span><span class="supported-langs__title">Türkçe</span></a></li><li class="supported-langs__item"><a class="supported-langs__link" href="https://uk.javascript.info/"><span class="supported-langs__brief">UK</span><span class="supported-langs__title">Українська</span></a></li></ul><ul class="supported-langs__list" style="height:20px"><li class="supported-langs__item supported-langs__item_current"><a class="supported-langs__link" href="https://zh.javascript.info/"><span class="supported-langs__brief">ZH</span><span class="supported-langs__title">简体中文</span></a></li></ul></div><div class="supported-langs__text">我们希望将这个开源项目提供给全世界的人。请帮助我们将教程的内容 <a href="https://javascript.info/translate#help" rel="noopener noreferrer" target="_blank">翻译为你所掌握的语言</a> 对应的版本。</div></div></div></div></div></div><div class="sitetoolbar__logo-wrap"><a class="sitetoolbar__link sitetoolbar__link_logo" href="/"><img class="sitetoolbar__logo sitetoolbar__logo_normal" src="/img/sitetoolbar__logo_en.svg" width="200" alt="" role="presentation"/><img class="sitetoolbar__logo sitetoolbar__logo_normal sitetoolbar__logo_dark" src="/img/sitetoolbar__logo_en-white.svg" width="200" alt="" role="presentation"/><img class="sitetoolbar__logo sitetoolbar__logo_small" src="/img/sitetoolbar__logo_small_en.svg" width="70" alt="" role="presentation"/><img class="sitetoolbar__logo sitetoolbar__logo_small sitetoolbar__logo_dark" src="/img/sitetoolbar__logo_small_en-white.svg" width="70" alt="" role="presentation"/><script>Array.prototype.forEach.call(document.querySelectorAll("img.sitetoolbar__logo"),function(e){let t=document.createElement("object");t.type="image/svg+xml",t.className=e.className,t.style.cssText="left:0;top:0;position:absolute",t.onload=function(){t.onload=null,e.style.visibility="hidden"},t.data=e.src,e.parentNode.insertBefore(t,e)});</script></a></div><div class="sitetoolbar__nav-toggle-wrap"><button class="sitetoolbar__nav-toggle" type="button"></button></div><nav class="sitetoolbar__sections"><ul class="sitetoolbar__sections-list"></ul></nav><div class="sitetoolbar__right-button-wrap"><a class="sitetoolbar-right-button sitetoolbar-right-button_courses" href="/ebook"><span class="sitetoolbar-right-button__extra-text">购买</span>EPUB/PDF</a></div><div class="sitetoolbar__theme-switcher"><div class="theme-changer"><label class="theme-changer__label" for="theme-changer-input" data-tooltip="Change theme"><input class="theme-changer__input" type="checkbox" id="theme-changer-input" data-theme-changer="data-theme-changer"/><span class="theme-changer__icon theme-changer__icon_light-theme"></span><span class="theme-changer__icon theme-changer__icon_dark-theme"></span></label></div></div><div class="sitetoolbar__search-wrap"><div class="sitetoolbar__search-content"><button class="sitetoolbar__search-toggle" type="button"></button><form class="sitetoolbar__search" method="GET" action="/search"><div class="sitetoolbar__search-input"><div class="text-input"><input class="text-input__control" name="query" placeholder="在 Javascript.info 网站中搜索" required="required" type="text"/></div><button class="sitetoolbar__find" type="submit">搜索</button></div></form></div></div></div><div class="tablet-menu"><div class="tablet-menu__line"><div class="tablet-menu__content"><form class="tablet-menu-search" action="/search/"><input class="tablet-menu-search__input" type="search" name="query" placeholder="在教程中搜索" required="required"/><button class="tablet-menu-search__button" type="submit" name="type" value="articles">搜索</button></form></div></div><div class="tablet-menu__line"><div class="tablet-menu__content"><a class="map" href="/tutorial/map" data-action="tutorial-map"><span class="map__text">教程路线图</span></a></div></div><div class="tablet-menu__line"><div class="tablet-menu__content"><div class="theme-changer theme-changer_tablet-menu theme-changer_has-label"><label class="theme-changer__label" for="theme-changer-input-tablet" data-tooltip="Change theme"><input class="theme-changer__input" type="checkbox" id="theme-changer-input-tablet" data-theme-changer="data-theme-changer"/><span class="theme-changer__icon theme-changer__icon_light-theme"></span><span class="theme-changer__icon theme-changer__icon_dark-theme"></span><span class="theme-changer__label-text theme-changer__label-text_light-theme">Light theme</span><span class="theme-changer__label-text theme-changer__label-text_dark-theme">Dark theme</span></label></div></div></div><div class="tablet-menu__line"><div class="tablet-menu__content"><div class="share-icons"><span class="share-icons__title">分享</span><a class="share share_tw" href="https://twitter.com/share?url=https%3A%2F%2Fzh.javascript.info%2F" rel="nofollow"></a><a class="share share_fb" href="https://www.facebook.com/sharer/sharer.php?s=100&p%5Burl%5D=https%3A%2F%2Fzh.javascript.info%2F" rel="nofollow"></a></div></div></div><div class="tablet-menu__line"><div class="tablet-menu__content"><select class="tablet-menu__nav input-select input-select input-select_small" onchange="if(this.value) window.location.href=this.value"><option value="https://ar.javascript.info/">عربي</option><option value="https://javascript.info/">English</option><option value="https://es.javascript.info/">Español</option><option value="https://fa.javascript.info/">فارسی</option><option value="https://fr.javascript.info/">Français</option><option value="https://id.javascript.info/">Indonesia</option><option value="https://it.javascript.info/">Italiano</option><option value="https://ja.javascript.info/">日本語</option><option value="https://ko.javascript.info/">한국어</option><option value="https://learn.javascript.ru/">Русский</option><option value="https://tr.javascript.info/">Türkçe</option><option value="https://uk.javascript.info/">Українська</option><option value="https://zh.javascript.info/" selected>简体中文</option></select></div></div></div></div><div class="page page_contains_header"><script>if(localStorage.noSidebar){document.querySelector(".page").classList.remove("page_sidebar_on");let e=document.querySelector(".page-wrapper");e&&e.classList.remove("page-wrapper_sidebar_on")}setTimeout(function(){document.querySelector(".page").classList.add("page_sidebar-animation-on")});</script><div class="frontpage-banner"><div class="frontpage-banner__inner"><div class="frontpage-banner__info"><div class="frontpage-banner__col"><h1 class="frontpage-banner__title">现代 JavaScript 教程</h1><p class="frontpage-banner__text frontpage-banner__text_lg">以最新的 JavaScript 标准为基准。通过简单但足够详细的内容,为你讲解从基础到高阶的 JavaScript 相关知识。</p><form class="frontpage-search" action="/search/"><div class="text-input text-input_big"><input class="text-input__frontpage-search__input text-input__control" type="search" name="query" placeholder="在教程中搜索" required="required"/></div><button class="frontpage-search__button button button_action button_big" type="submit" name="type" value="article">搜索</button></form></div><div class="frontpage-banner__col"><div class="frontpage-banner__updated-at">最后修改在 2025年4月4日</div><div class="frontpage-banner__list"><a class="frontpage-banner__list-item" href="/ebook"><i class="frontpage-banner__buy-ebook"></i><span>购买</span><span>EPUB/PDF</span></a><div class="frontpage-banner__list-item"><div class="frontpage-share"><span class="frontpage-share__title">分享:</span><a class="frontpage-share__icon frontpage-share__icon_tw" href="https://twitter.com/share?url=https%3A%2F%2Fzh.javascript.info%2F" rel="nofollow"></a><a class="frontpage-share__icon frontpage-share__icon_fb" href="https://www.facebook.com/sharer/sharer.php?s=100&p%5Burl%5D=https%3A%2F%2Fzh.javascript.info%2F" rel="nofolllow"></a></div></div><a class="frontpage-banner__list-item github" href="https://github.com/javascript-tutorial/zh.javascript.info/tree/master"><span class="frontpage-banner__count">10150 ★</span><span class="frontpage-banner__text">github</span></a><a class="frontpage-banner__list-item wechat-qq" href="#"><i class="frontpage-banner__wechat-qq"></i><span>WeChat 和 QQ</span></a></div></div></div><div class="frontpage-banner__sub"><h2 class="frontpage-banner__subtitle">目录</h2><p class="frontpage-banner__text">课程的核心内容包含 2 部分,涵盖了 JavaScript 编程语言相关知识和浏览器行为。此外还有一系列的专题文章。</p></div></div></div><div class="page__inner"><main class="main main_frontpage"><div class="content frontpage"><div class="frontpage-content"><div class="tabs"><nav class="tabs__menu"><div class="tabs__menu-inner"><div class="tabs__menu-inner-scroll"><a class="tabs__menu-button active" href="#tab-1"><span class="tabs__menu-button-title">第 一 部分</span><span>JavaScript 编程语言</span></a><a class="tabs__menu-button" href="#tab-2"><span class="tabs__menu-button-title">第 二 部分</span><span>浏览器:文档,事件,接口</span></a><a class="tabs__menu-button" href="#tab-3"><span class="tabs__menu-button-title">第 三 部分</span><span>其他文章</span></a></div></div></nav><div class="tabs__content" id="tab-1"><section class="tabs__content-section"><div class="tabs__content-inner"><div><h2 class="frontpage-content__title">JavaScript 编程语言</h2><div class="frontpage-content__description"><p>在这儿我们将从头开始学习 JavaScript,也会学习 OOP 等相关高级概念。</p> <p>本教程专注于语言本身,我们默认使用最小环境。</p> </div><div class="list"><div class="list__item"><div class="list__title"><a class="list__link" href="/getting-started">简介</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/intro">JavaScript 简介</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/manuals-specifications">手册与规范</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/code-editors">代码编辑器</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/devtools">开发者控制台</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/first-steps">JavaScript 基础知识</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/hello-world">Hello, world!</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/structure">代码结构</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/strict-mode">现代模式,"use strict"</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/variables">变量</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/types">数据类型</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/alert-prompt-confirm">交互:alert、prompt 和 confirm</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/type-conversions">类型转换</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/operators">基础运算符,数学运算</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/comparison">值的比较</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/ifelse">条件分支:if 和 '?'</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/logical-operators">逻辑运算符</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/nullish-coalescing-operator">空值合并运算符 '??'</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/while-for">循环:while 和 for</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/switch">"switch" 语句</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/function-basics">函数</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/function-expressions">函数表达式</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/arrow-functions-basics">箭头函数,基础知识</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/javascript-specials">JavaScript 特性</a></div></li><li class="list-sub__item"><a class="list-sub__more" href="#">更多内容…</a></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/code-quality">代码质量</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/debugging-chrome">在浏览器中调试</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/coding-style">代码风格</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/comments">注释</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/ninja-code">忍者代码</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/testing-mocha">使用 Mocha 进行自动化测试</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/polyfills">Polyfill 和转译器</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/object-basics">Object(对象):基础知识</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/object">对象</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/object-copy">对象引用和复制</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/garbage-collection">垃圾回收</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/object-methods">对象方法,"this"</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/constructor-new">构造器和操作符 "new"</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/optional-chaining">可选链 "?."</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/symbol">symbol 类型</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/object-toprimitive">对象 —— 原始值转换</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/data-types">数据类型</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/primitives-methods">原始类型的方法</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/number">数字类型</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/string">字符串</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/array">数组</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/array-methods">数组方法</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/iterable">Iterable object(可迭代对象)</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/map-set">Map and Set(映射和集合)</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/weakmap-weakset">WeakMap and WeakSet(弱映射和弱集合)</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/keys-values-entries">Object.keys,values,entries</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/destructuring-assignment">解构赋值</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/date">日期和时间</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/json">JSON 方法,toJSON</a></div></li><li class="list-sub__item"><a class="list-sub__more" href="#">更多内容…</a></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/advanced-functions">函数进阶内容</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/recursion">递归和堆栈</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/rest-parameters-spread">Rest 参数与 Spread 语法</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/closure">变量作用域,闭包</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/var">老旧的 "var"</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/global-object">全局对象</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/function-object">函数对象,NFE</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/new-function">"new Function" 语法</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/settimeout-setinterval">调度:setTimeout 和 setInterval</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/call-apply-decorators">装饰器模式和转发,call/apply</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/bind">函数绑定</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/arrow-functions">深入理解箭头函数</a></div></li><li class="list-sub__item"><a class="list-sub__more" href="#">更多内容…</a></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/object-properties">对象属性配置</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/property-descriptors">属性标志和属性描述符</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/property-accessors">属性的 getter 和 setter</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/prototypes">原型,继承</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/prototype-inheritance">原型继承</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/function-prototype">F.prototype</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/native-prototypes">原生的原型</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/prototype-methods">原型方法,没有 __proto__ 的对象</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/classes">类</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/class">Class 基本语法</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/class-inheritance">类继承</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/static-properties-methods">静态属性和静态方法</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/private-protected-properties-methods">私有的和受保护的属性和方法</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/extend-natives">扩展内建类</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/instanceof">类检查:"instanceof"</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/mixins">Mixin 模式</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/error-handling">错误处理</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/try-catch">错误处理,"try...catch"</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/custom-errors">自定义 Error,扩展 Error</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/async">Promise,async/await</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/callbacks">简介:回调</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/promise-basics">Promise</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/promise-chaining">Promise 链</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/promise-error-handling">使用 promise 进行错误处理</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/promise-api">Promise API</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/promisify">Promisification</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/microtask-queue">微任务(Microtask)</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/async-await">async/await</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/generators-iterators">Generator,高级 iteration</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/generators">generator</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/async-iterators-generators">异步迭代和 generator</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/modules">模块</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/modules-intro">模块 (Module) 简介</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/import-export">导出和导入</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/modules-dynamic-imports">动态导入</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/js-misc">杂项</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/proxy">Proxy 和 Reflect</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/eval">Eval:执行代码字符串</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/currying-partials">柯里化(Currying)</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/reference-type">Reference Type</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/bigint">BigInt</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/unicode">Unicode —— 字符串内幕</a></div></li></ul></div></div></div></div></section></div><div class="tabs__content" id="tab-2"><section class="tabs__content-section"><div class="tabs__content-inner"><div><h2 class="frontpage-content__title">浏览器:文档,事件,接口</h2><div class="frontpage-content__description"><p>学习如何管理浏览器页面:添加元素,操纵元素的大小和位置,动态创建接口并与访问者互动。</p> </div><div class="list"><div class="list__item"><div class="list__title"><a class="list__link" href="/document">Document</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/browser-environment">浏览器环境,规格</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/dom-nodes">DOM 树</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/dom-navigation">遍历 DOM</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/searching-elements-dom">搜索:getElement*,querySelector*</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/basic-dom-node-properties">节点属性:type,tag 和 content</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/dom-attributes-and-properties">特性和属性(Attributes and properties)</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/modifying-document">修改文档(document)</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/styles-and-classes">样式和类</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/size-and-scroll">元素大小和滚动</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/size-and-scroll-window">Window 大小和滚动</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/coordinates">坐标</a></div></li><li class="list-sub__item"><a class="list-sub__more" href="#">更多内容…</a></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/events">事件简介</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/introduction-browser-events">浏览器事件简介</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/bubbling-and-capturing">冒泡和捕获</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/event-delegation">事件委托</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/default-browser-action">浏览器默认行为</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/dispatch-events">创建自定义事件</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/event-details">UI 事件</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/mouse-events-basics">鼠标事件</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/mousemove-mouseover-mouseout-mouseenter-mouseleave">移动鼠标:mouseover/out,mouseenter/leave</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/mouse-drag-and-drop">鼠标拖放事件</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/pointer-events">指针事件</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/keyboard-events">键盘:keydown 和 keyup</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/onscroll">滚动</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/forms-controls">表单,控件</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/form-elements">表单属性和方法</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/focus-blur">聚焦:focus/blur</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/events-change-input">事件:change,input,cut,copy,paste</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/forms-submit">表单:事件和方法提交</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/loading">加载文档和其他资源</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/onload-ondomcontentloaded">页面生命周期:DOMContentLoaded,load,beforeunload,unload</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/script-async-defer">脚本:async,defer</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/onload-onerror">资源加载:onload,onerror</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/ui-misc">杂项</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/mutation-observer">DOM 变动观察器(Mutation observer)</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/selection-range">选择(Selection)和范围(Range)</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/event-loop">事件循环:微任务和宏任务</a></div></li></ul></div></div></div></div></section></div><div class="tabs__content" id="tab-3"><section class="tabs__content-section tabs__content-section_no-shadow"><div class="tabs__content-inner"><div><h2 class="frontpage-content__title">其他文章</h2><div class="frontpage-content__description">教程的前两部分未涉及的其他主题的内容列表。此处没有明确的层次结构,你可以按你需要的顺序阅读文章。</div><div class="list"><div class="list__item"><div class="list__title"><a class="list__link" href="/frames-and-windows">Frame 和 window</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/popup-windows">弹窗和 window 的方法</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/cross-window-communication">跨窗口通信</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/clickjacking">点击劫持攻击</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/binary">二进制数据,文件</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/arraybuffer-binary-arrays">ArrayBuffer,二进制数组</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/text-decoder">TextDecoder 和 TextEncoder</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/blob">Blob</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/file">File 和 FileReader</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/network">网络请求</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/fetch">Fetch</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/formdata">FormData</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/fetch-progress">Fetch:下载进度</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/fetch-abort">Fetch:中止(Abort)</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/fetch-crossorigin">Fetch:跨源请求</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/fetch-api">Fetch API</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/url">URL 对象</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/xmlhttprequest">XMLHttpRequest</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/resume-upload">可恢复的文件上传</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/long-polling">长轮询(Long polling)</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/websocket">WebSocket</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/server-sent-events">Server Sent Events</a></div></li><li class="list-sub__item"><a class="list-sub__more" href="#">更多内容…</a></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/data-storage">在浏览器中存储数据</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/cookie">Cookie,document.cookie</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/localstorage">LocalStorage,sessionStorage</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/indexeddb">IndexedDB</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/animation">动画</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/bezier-curve">贝塞尔曲线</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/css-animations">CSS 动画</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/js-animation">JavaScript 动画</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/web-components">Web components</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/webcomponents-intro">从星球轨道的高度讲起</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/custom-elements">Custom elements</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/shadow-dom">影子 DOM(Shadow DOM)</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/template-element">模板元素</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/slots-composition">Shadow DOM 插槽,组成</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/shadow-dom-style">给 Shadow DOM 添加样式</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/shadow-dom-events">Shadow DOM 和事件(events)</a></div></li></ul></div><div class="list__item"><div class="list__title"><a class="list__link" href="/regular-expressions">正则表达式</a></div><ul class="list-sub"><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-introduction">模式(Patterns)和修饰符(flags)</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-character-classes">字符类</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-unicode">Unicode:修饰符 "u" 和类 \p{...}</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-anchors">锚点:字符串开始 ^ 和末尾 $</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-multiline-mode">锚点 ^ $ 的多行模式,修饰符 "m"</a></div></li><li class="list-sub__item"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-boundary">词边界:\b</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-escaping">转义,特殊字符</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-character-sets-and-ranges">集合和范围 [...]</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-quantifiers">量词 +, *, ? 和 {n}</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-greedy-and-lazy">贪婪量词和惰性量词</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-groups">捕获组</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-backreferences">模式中的反向引用:\N 和 \k<name></a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-alternation">选择 (OR) |</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-lookahead-lookbehind">前瞻断言与后瞻断言</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-catastrophic-backtracking">灾难性回溯</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-sticky">粘性修饰符 "y",在位置处搜索</a></div></li><li class="list-sub__item list-sub__item_phone_hidden"><div class="list-sub__title"><a class="list-sub__link" href="/regexp-methods">正则表达式和字符串的方法</a></div></li><li class="list-sub__item"><a class="list-sub__more" href="#">更多内容…</a></li></ul></div></div></div></div></section></div></div><section class="frontpage-content__container frontpage-content__container_no-shadow"><div class="frontpage-content__inner"><div class="subscribe subscribe_fancy"><h3 class="subscribe__title">关注 javascript.ru 的更新</h3><div class="subscribe__greyed-text">我们不发送广告,只提供重要信息。您可以自行选择接收内容:</div><form class="subscribe__form" method="POST" action="/newsletter/subscribe" data-newsletter-subscribe-form><input type="hidden" name="_csrf"/><input type="hidden" name="replace" value="1"/><div class="subscribe__email-input"><div class="subscribe__newsletters"><div class="multiselect subscribe__multiselect"><div class="multiselect__active-button">常规更新</div><div class="multiselect__container"><select class="multiselect__select phone-only" name="slug" size="1" multiple></select></div></div><div class="subscribe__input"><div class="text-input text-input_big text-input_plain"><input class="text-input__control" type="email" placeholder="你的@email" name="email" required="required"/></div></div><div class="subscribe__button"><button class="button button_action button_big" type="submit"><span class="button__text">订阅</span></button></div></div></div></form><div class="subscribe__greyed-text subscribe__greyed-text_small">订阅时,您同意 <a href="/terms" target="_blank">用户协议</a>。</div></div></div></section></div><script type="application/ld+json">{ "@context": "http://schema.org", "@type": "WebSite", "url": "https://zh.javascript.info/", "potentialAction": { "@type": "SearchAction", "target": "https://zh.javascript.info/search?query={search_term_string}", "query-input": "required name=search_term_string" } }</script></div><div class="article-tablet-foot tablet-only"><div class="article-tablet-foot__layout"><div class="share-icons"><span class="share-icons__title">分享</span><a class="share share_tw" href="https://twitter.com/share?url=https%3A%2F%2Fzh.javascript.info%2F" rel="nofollow"></a><a class="share share_fb" href="https://www.facebook.com/sharer/sharer.php?s=100&p%5Burl%5D=https%3A%2F%2Fzh.javascript.info%2F" rel="nofollow"></a></div><div class="article-tablet-foot__map"><a class="map" href="/tutorial/map" data-action="tutorial-map"><span class="map__text">教程路线图</span></a></div></div></div><div class="comments formatted" id="comments"><div class="comments__header"><h2 class="comments__header-title"><a href="#comments" name="comments">评论</a></h2><div class="comments__read-before"><span class="comments__read-before-link">在评论之前先阅读本内容…</span><div class="comments__read-before-popup"><div class="comments__read-before-popup-i"><ul><li>如果你发现教程有错误,或者有其他需要修改和提升的地方 — 请 <a href="https://github.com/javascript-tutorial/zh.javascript.info/issues">提交一个 GitHub issue</a> 或 pull request,而不是在这评论。</li><li>如果你对教程的内容有不理解的地方 — 请详细说明。</li><li>使用 <code><code></code> 标签插入只有几个词的代码,插入多行代码可以使用 <code><pre></code> 标签,对于超过 10 行的代码,建议你使用沙箱(<a href='https://plnkr.co/edit/?p=preview'>plnkr</a>,<a href='https://jsbin.com'>JSBin</a>,<a href='http://codepen.io'>codepen</a>…)</li></ul></div></div></div></div><div id="disqus_thread"></div><script>var disqus_config = function() { if (!this.page) this.page = {}; Object.assign(this.page, {"url":"https:\/\/zh.javascript.info\/","identifier":"","title":"\u73b0\u4ee3 JavaScript \u6559\u7a0b"}); };</script><script>var disqus_shortname = "zh-javascript-info";</script><script>var disqus_enabled = true;</script></div></script></main></div></div></div><div class="page-footer"><ul class="page-footer__list"><li class="page-footer__item page-footer__item_copy">© 2007—2025 Ilya Kantor</li><li class="page-footer__item page-footer__item_about"><a class="page-footer__link" href="/about">关于本项目</a></li><li class="page-footer__item page-footer__item_contact"><a class="page-footer__link" href="/about#contact-us">联系我们</a></li></ul></div></body></html>