{"id":77149,"date":"2026-02-24T01:50:16","date_gmt":"2026-02-23T17:50:16","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/77149.html"},"modified":"2026-02-24T01:50:16","modified_gmt":"2026-02-23T17:50:16","slug":"web-apis-day1","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/77149.html","title":{"rendered":"web APIS Day1"},"content":{"rendered":"<h2>\u6709\u5173\u53d8\u91cf\u7684\u58f0\u660e<\/h2>\n<p>\u53d8\u91cf\u7684\u58f0\u660e\u6709\u51e0\u79cd\u65b9\u5f0f&#xff0c;\u4f8b\u5982\u7528let&#xff0c;const\u3002\u5728\u4ee5\u524d\u7684\u7248\u672c\u8fd8\u7528var\u6765\u58f0\u660e<\/p>\n<p>var\u7684\u7279\u70b9&#xff1a;1\u3001\u5141\u8bb8\u91cd\u590d\u58f0\u660e\u00a0 2\u3001\u5b58\u5728\u53d8\u91cf\u63d0\u5347&#xff0c;\u5373\u53d8\u91cf\u53ef\u4ee5\u518d\u58f0\u660e\u524d\u4f7f\u7528<\/p>\n<p>\u7f3a\u70b9&#xff1a;1\u3001var \u58f0\u660e\u7684\u53d8\u91cf\u4f1a\u88ab\u63d0\u5347\u5230\u51fd\u6570\u6216\u5168\u5c40\u4f5c\u7528\u57df\u7684\u9876\u90e8&#xff0c;\u5bfc\u81f4\u53d8\u91cf\u5728\u58f0\u660e\u524d\u5c31\u53ef\u4ee5\u8bbf\u95ee&#xff0c;\u4f46\u503c\u4e3a undefined\u3002\u8fd9\u79cd\u884c\u4e3a\u5bb9\u6613\u5f15\u53d1\u903b\u8f91\u9519\u8bef<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 2\u3001var \u7684\u4f5c\u7528\u57df\u4ec5\u9650\u4e8e\u51fd\u6570\u6216\u5168\u5c40&#xff0c;\u800c\u975e\u5757\u7ea7&#xff08;\u5982 if\u3001for \u7b49&#xff09;\u3002\u8fd9\u4f1a\u5bfc\u81f4\u53d8\u91cf\u5728\u5757\u5916\u4ecd\u53ef\u8bbf\u95ee&#xff0c;\u53ef\u80fd\u5f15\u53d1\u610f\u5916\u8986\u76d6<\/p>\n<p>let\u7684\u7279\u70b9&#xff1a;1\u3001\u4e0d\u5141\u8bb8\u91cd\u590d\u58f0\u660e\u00a0 2\u3001\u4e0d\u5b58\u5728\u53d8\u91cf\u63d0\u5347&#xff0c;\u5fc5\u987b\u5148\u58f0\u660e\u540e\u4f7f\u7528<\/p>\n<p>const\u7684\u7279\u70b9&#xff1a;1\u3001\u5fc5\u987b\u521d\u59cb\u5316\u8d4b\u503c\u00a0 2\u3001\u5757\u7ea7\u4f5c\u7528\u57df\u00a0 3\u3002\u9002\u5408\u7528\u4e8e\u58f0\u660e\u4e0d\u53ef\u53d8\u7684\u5e38\u91cf\u6216\u5f15\u7528\u7c7b\u578b<\/p>\n<p>\u5728\u6b64\u63a8\u8350\u4f7f\u7528const\u6765\u58f0\u660e\u53d8\u91cf&#xff0c;\u53ef\u4ee5\u907f\u514d\u610f\u5916\u4fee\u6539&#xff0c;\u6216\u8005\u4f7f\u7528let&#xff0c;var\u4e0d\u63a8\u8350\u4f7f\u7528<\/p>\n<h2>DOM\u6811\u548cDOM\u5bf9\u8c61<\/h2>\n<h3>\u83b7\u53d6DOM\u5143\u7d20<\/h3>\n<p>\u5728CSS\u4e2d\u6211\u4eec\u4e00\u822c\u4f7f\u7528document.querySelector(&#039;selector&#039;)\u83b7\u53d6\u7b2c\u4e00\u4e2a\u5339\u914d\u5143\u7d20&#xff0c;\u6216document.querySelectorAll(&#039;selector&#039;)\u83b7\u53d6\u6240\u6709\u5339\u914d\u5143\u7d20&#xff08;\u9759\u6001NodeList&#xff09;&#xff0c;\u652f\u6301\u590d\u6742CSS\u9009\u62e9\u5668<\/p>\n<h4>\u7c7b\u9009\u62e9\u5668<\/h4>\n<p>const firstItem &#061; document.querySelector(&#039;.list-item&#039;);<br \/>\nconst allItems &#061; document.querySelectorAll(&#039;.list-item&#039;);<\/p>\n<h4>id\u9009\u62e9\u5668\u00a0 \u00a0\u00a0<\/h4>\n<p>\u4f7f\u7528#\u524d\u7f00\u5339\u914d\u5143\u7d20\u7684id\u5c5e\u6027<\/p>\n<p>const name &#061; document.querSelector(&#039;#username&#039;)<\/p>\n<h4>\u6807\u7b7e\u9009\u62e9\u5668<\/h4>\n<p>\u76f4\u63a5\u4f7f\u7528HTML\u7c7b\u540d<\/p>\n<p>const body &#061; document.querSelector(&#039;body&#039;)<\/p>\n<h4>\u5176\u5b83\u65b9\u5f0f<\/h4>\n<p>\u901a\u8fc7ID\u83b7\u53d6\u5143\u7d20<br \/>\n\u4f7f\u7528document.getElementById(&#039;id&#039;)\u65b9\u6cd5&#xff0c;\u4f20\u5165\u5143\u7d20\u7684ID\u5b57\u7b26\u4e32\u3002\u8fd4\u56de\u5339\u914dID\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20&#xff0c;\u82e5\u4e0d\u5b58\u5728\u5219\u8fd4\u56denull<\/p>\n<p>const element &#061; document.getElementById(&#039;header&#039;);<\/p>\n<p>\u901a\u8fc7\u7c7b\u540d\u83b7\u53d6\u5143\u7d20<br \/>\n\u4f7f\u7528document.getElementsByClassName(&#039;class&#039;)\u65b9\u6cd5&#xff0c;\u4f20\u5165\u7c7b\u540d\u5b57\u7b26\u4e32\u3002\u8fd4\u56de\u5305\u542b\u6240\u6709\u5339\u914d\u7c7b\u7684\u52a8\u6001HTML\u96c6\u5408&#xff08;\u7c7b\u6570\u7ec4\u5bf9\u8c61&#xff09;<\/p>\n<p>const elements &#061; document.getElementsByClassName(&#039;menu-item&#039;);<\/p>\n<p>\u901a\u8fc7\u6807\u7b7e\u540d\u83b7\u53d6\u5143\u7d20<br \/>\n\u4f7f\u7528document.getElementsByTagName(&#039;tag&#039;)\u65b9\u6cd5&#xff0c;\u4f20\u5165\u6807\u7b7e\u540d&#xff08;\u5982div&#xff09;\u3002\u8fd4\u56de\u5305\u542b\u6240\u6709\u5339\u914d\u6807\u7b7e\u7684\u52a8\u6001HTML\u96c6\u5408<\/p>\n<p>const divs &#061; document.getElementsByTagName(&#039;div&#039;);<\/p>\n<h2>DOM\u5143\u7d20\u5185\u5bb9\u53ca\u5c5e\u6027\u7684\u4fee\u6539<\/h2>\n<h3>DOM\u5143\u7d20\u5185\u5bb9\u4fee\u6539<\/h3>\n<p>\u4fee\u6539DOM\u5143\u7d20\u5185\u5bb9\u4e3b\u8981\u901a\u8fc7innerHTML\u3001textContent\u548cinnerText\u5c5e\u6027\u5b9e\u73b0\u3002innerHTML\u53ef\u89e3\u6790HTML\u6807\u7b7e&#xff0c;\u9002\u5408\u52a8\u6001\u63d2\u5165\u5e26\u683c\u5f0f\u7684\u5185\u5bb9\u3002textContent\u4f1a\u539f\u6837\u663e\u793a\u6587\u672c&#xff0c;\u5ffd\u7565HTML\u6807\u7b7e\u3002innerText\u4f1a\u8003\u8651CSS\u6837\u5f0f&#xff0c;\u4e0d\u663e\u793a\u9690\u85cf\u5143\u7d20\u5185\u5bb9\u3002<\/p>\n<p>\/\/ \u4fee\u6539\u5143\u7d20\u5185\u5bb9\u793a\u4f8b<br \/>\nconst element &#061; document.getElementById(&#039;target&#039;);<br \/>\nelement.innerHTML &#061; &#039;&lt;strong&gt;\u52a0\u7c97\u6587\u672c&lt;\/strong&gt;&#039;; \/\/ \u89e3\u6790HTML<br \/>\nelement.textContent &#061; &#039;&lt;strong&gt;\u7eaf\u6587\u672c\u663e\u793a&lt;\/strong&gt;&#039;; \/\/ \u4e0d\u89e3\u6790HTML<\/p>\n<h3>DOM\u5c5e\u6027\u4fee\u6539<\/h3>\n<p>\u6807\u51c6HTML\u5c5e\u6027\u53ef\u901a\u8fc7\u5143\u7d20\u5bf9\u8c61\u76f4\u63a5\u8bbf\u95ee\u6216\u4f7f\u7528setAttribute\u65b9\u6cd5\u3002\u81ea\u5b9a\u4e49\u5c5e\u6027\u9700\u901a\u8fc7dataset\u6216setAttribute\u64cd\u4f5c\u3002\u79fb\u9664\u5c5e\u6027\u4f7f\u7528removeAttribute\u65b9\u6cd5<\/p>\n<p>\/\/ \u4fee\u6539\u6807\u51c6\u5c5e\u6027<br \/>\nconst img &#061; document.querySelector(&#039;img&#039;);<br \/>\nimg.src &#061; &#039;new-image.jpg&#039;; \/\/ \u76f4\u63a5\u5c5e\u6027\u8d4b\u503c<br \/>\nimg.setAttribute(&#039;alt&#039;, &#039;\u65b0\u56fe\u7247\u63cf\u8ff0&#039;); \/\/ \u901a\u7528\u65b9\u6cd5<\/p>\n<p>\/\/ \u64cd\u4f5c\u81ea\u5b9a\u4e49\u5c5e\u6027<br \/>\nimg.setAttribute(&#039;data-custom&#039;, &#039;value&#039;);\u7b2c\u4e00\u4e2a\u4e3a\u8981\u8bbe\u7f6e\u7684\u5c5e\u6027\u540d\u79f0&#xff0c;\u7b2c\u4e8c\u4e2a\u4e3a\u8981\u4e3a\u7b2c\u4e00\u4e2a\u53c2\u6570\u8bbe\u7f6e\u7684\u503c<br \/>\nconst customValue &#061; img.dataset.custom; \/\/ \u901a\u8fc7dataset\u8bbf\u95ee<\/p>\n<h6>\u6279\u91cf\u4fee\u6539\u591a\u4e2a\u5143\u7d20<\/h6>\n<p>\u901a\u8fc7querySelectorAll\u83b7\u53d6\u8282\u70b9\u5217\u8868\u540e&#xff0c;\u53ef\u4ee5\u4f7f\u7528for\u5faa\u73af\u6765\u5faa\u73af\u5904\u7406<\/p>\n<h6>\u6837\u5f0f\u7c7b\u540d\u64cd\u4f5c<\/h6>\n<p>\u901a\u8fc7classListAPI\u53ef\u7cbe\u786e\u63a7\u5236CSS\u7c7b&#xff0c;\u652f\u6301add\u3001remove\u3001toggle\u7b49\u65b9\u6cd5\u3002\u76f4\u63a5\u4fee\u6539className\u4f1a\u8986\u76d6\u5168\u90e8\u7c7b\u540d<\/p>\n<p>add(className)\u00a0\u00a0 \u00a0\u6dfb\u52a0\u4e00\u4e2a \/ \u591a\u4e2a\u7c7b\u540d&#xff08;\u91cd\u590d\u6dfb\u52a0\u65e0\u6548\u679c&#xff09;\u00a0 \u00a0\u00a0<br \/>\nremove(className)\u00a0\u00a0 \u00a0\u5220\u9664\u4e00\u4e2a \/ \u591a\u4e2a\u7c7b\u540d&#xff08;\u5220\u9664\u4e0d\u5b58\u5728\u7684\u7c7b\u540d\u65e0\u62a5\u9519&#xff09;\u00a0 \u00a0<br \/>\ntoggle(className)\u00a0\u00a0 \u00a0\u5207\u6362\u7c7b\u540d&#xff08;\u5b58\u5728\u5219\u5220\u9664&#xff0c;\u4e0d\u5b58\u5728\u5219\u6dfb\u52a0&#xff09;\u00a0<br \/>\ncontains(className)\u00a0\u00a0 \u00a0\u5224\u65ad\u662f\u5426\u5305\u542b\u67d0\u4e2a\u7c7b\u540d&#xff08;\u8fd4\u56de\u5e03\u5c14\u503c&#xff09;<\/p>\n<p>const box &#061; document.getElementById(&#039;box&#039;);<br \/>\nbox.classList.add(&#039;active&#039;); \/\/ \u6dfb\u52a0\u7c7b<br \/>\nbox.classList.remove(&#039;inactive&#039;); \/\/ \u79fb\u9664\u7c7b<br \/>\nbox.classList.toggle(&#039;visible&#039;); \/\/ \u5207\u6362\u7c7b<br \/>\nbox.className &#061; &#039;new-class&#039;;\/\/\u66f4\u6362\u7c7b<\/p>\n<p>\u8fdb\u9636\u7528\u6cd5&#xff1a;replace \u66ff\u6362\u7c7b\u540d<\/p>\n<p>classList.replace(oldClass, newClass) \u53ef\u4ee5\u76f4\u63a5\u66ff\u6362\u67d0\u4e2a\u7c7b\u540d&#xff0c;\u9002\u5408\u9700\u8981 \u201c\u5207\u6362\u6837\u5f0f\u7c7b\u578b\u201d \u7684\u573a\u666f<\/p>\n<p>\/\/ \u5c06box\u7684big\u7c7b\u66ff\u6362\u4e3asmall\u7c7b<br \/>\nbox.classList.replace(&#039;big&#039;, &#039;small&#039;);<br \/>\nconsole.log(box.className); \/\/ \u8f93\u51fa&#xff1a;box small<\/p>\n<p>\u5bf9\u6bd4\u4f20\u7edf className&#xff08;\u4e3a\u4ec0\u4e48\u63a8\u8350 classList&#xff09;<\/p>\n<p>\u76f4\u63a5\u4fee\u6539 className \u9700\u8981\u624b\u52a8\u62fc\u63a5\u5b57\u7b26\u4e32&#xff0c;\u5bb9\u6613\u51fa\u9519&#xff0c;\u800c classList \u66f4\u5b89\u5168&#xff1a;<\/p>\n<p>\/\/ \u4f20\u7edf\u65b9\u5f0f&#xff08;\u7f3a\u70b9&#xff1a;\u4f1a\u8986\u76d6\u539f\u6709\u7c7b\u540d&#xff09;<br \/>\nbox.className &#061; &#039;active&#039;; \/\/ \u539f\u672c\u7684box\u7c7b\u4f1a\u88ab\u8986\u76d6&#xff0c;\u53ea\u5269active<\/p>\n<p>\/\/ \u6539\u8fdb\u7684\u4f20\u7edf\u65b9\u5f0f&#xff08;\u9700\u8981\u624b\u52a8\u62fc\u63a5&#xff0c;\u9ebb\u70e6&#xff09;<br \/>\nbox.className &#061; box.className &#043; &#039; active&#039;; \/\/ \u9700\u6ce8\u610f\u7a7a\u683c<\/p>\n<p>\/\/ classList\u65b9\u5f0f&#xff08;\u63a8\u8350&#xff1a;\u4fdd\u7559\u539f\u6709\u7c7b\u540d&#xff0c;\u4ec5\u6dfb\u52a0&#xff09;<br \/>\nbox.classList.add(&#039;active&#039;); \/\/ \u539f\u6709\u7c7b\u540d\u4e0d\u53d8&#xff0c;\u65b0\u589eactive<\/p>\n<p>\u6ce8\u610f\u4e8b\u9879<br \/>\n1.classList \u64cd\u4f5c\u7684\u662f\u7c7b\u540d&#xff08;\u5bf9\u5e94 CSS \u6837\u5f0f&#xff09;&#xff0c;\u4e0d\u662f DOM \u7684\u5176\u4ed6\u5c5e\u6027&#xff08;\u5982 id\u3001data-*&#xff09;&#xff1b;<br \/>\n2.\u7c7b\u540d\u53c2\u6570\u4e0d\u8981\u52a0 .&#xff08;\u6bd4\u5982\u5199 add(&#039;active&#039;) \u800c\u975e add(&#039;.active&#039;)&#xff09;&#xff1b;<br \/>\n3.\u6240\u6709\u65b9\u6cd5\u90fd\u652f\u6301\u4f20\u5165\u591a\u4e2a\u7c7b\u540d&#xff08;\u7528\u9017\u53f7\u5206\u9694&#xff09;&#xff0c;\u6bd4\u5982 add(&#039;a&#039;, &#039;b&#039;, &#039;c&#039;)&#xff1b;<br \/>\n4.\u517c\u5bb9\u6027&#xff1a;\u652f\u6301\u6240\u6709\u73b0\u4ee3\u6d4f\u89c8\u5668&#xff0c;IE10&#043; \u4e5f\u517c\u5bb9&#xff08;\u5b8c\u5168\u6ee1\u8db3\u65e5\u5e38\u5f00\u53d1&#xff09;<\/p>\n<h6>\u68c0\u67e5\u7c7b\u540d\u662f\u5426\u5b58\u5728<\/h6>\n<h6>contains\u65b9\u6cd5\u53ef\u4ee5\u68c0\u67e5\u5143\u7d20\u662f\u5426\u5305\u542b\u6307\u5b9a\u7684CSS\u7c7b&#xff0c;\u8fd4\u56de\u5e03\u5c14\u503c<\/h6>\n<p>if (element.classList.contains(&#039;active&#039;)) {<br \/>\n  console.log(&#039;Element has active class&#039;);<br \/>\n}<\/p>\n<h4>\u8868\u5355\u5143\u7d20\u503c\u64cd\u4f5c<\/h4>\n<p>\u8868\u5355\u63a7\u4ef6\u5982input\u3001select\u7b49\u9700\u901a\u8fc7value\u5c5e\u6027\u64cd\u4f5c\u3002\u590d\u9009\u6846\u548c\u5355\u9009\u6309\u94ae\u9700\u68c0\u67e5checked\u5c5e\u6027<\/p>\n<p>const input &#061; document.getElementById(&#039;username&#039;);<br \/>\ninput.value &#061; &#039;\u65b0\u7528\u6237&#039;; \/\/ \u4fee\u6539\u8f93\u5165\u503c<\/p>\n<p>const checkbox &#061; document.getElementById(&#039;agree&#039;);<br \/>\ncheckbox.checked &#061; true; \/\/ \u9009\u4e2d\u590d\u9009\u6846<\/p>\n<h4>\u4f7f\u7528 style \u5c5e\u6027\u4fee\u6539\u6837\u5f0f<\/h4>\n<p>\u5728 HTML \u548c JavaScript \u4e2d&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u00a0style\u00a0\u5c5e\u6027\u76f4\u63a5\u4fee\u6539\u5143\u7d20\u7684\u6837\u5f0f\u3002\u8fd9\u79cd\u65b9\u5f0f\u9002\u7528\u4e8e\u52a8\u6001\u8c03\u6574\u6837\u5f0f\u6216\u8986\u76d6\u5185\u8054\u6837\u5f0f<\/p>\n<p>element.style.property &#061; value;<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;body&gt;<br \/>\n  &lt;div id&#061;&#034;myBox&#034; style&#061;&#034;width: 100px; height: 100px; border: 1px solid #000;&#034;&gt;\u6d4b\u8bd5\u76d2\u5b50&lt;\/div&gt;<br \/>\n  &lt;button onclick&#061;&#034;changeStyle()&#034;&gt;\u4fee\u6539\u6837\u5f0f&lt;\/button&gt;<\/p>\n<p>  &lt;script&gt;<br \/>\n    const box &#061; document.getElementById(&#039;myBox&#039;);<\/p>\n<p>    function changeStyle() {<br \/>\n      \/\/ 1. \u4fee\u6539\u5355\u4e2a\u6837\u5f0f&#xff08;\u9a7c\u5cf0\u547d\u540d&#xff09;<br \/>\n      box.style.backgroundColor &#061; &#039;red&#039;; \/\/ \u80cc\u666f\u53d8\u7ea2<\/p>\n<p>      \/\/ 2. \u4fee\u6539\u591a\u4e2a\u6837\u5f0f&#xff08;\u76f4\u63a5\u94fe\u5f0f\/\u9010\u4e2a\u8d4b\u503c&#xff09;<br \/>\n      box.style.width &#061; &#039;200px&#039;;        \/\/ \u5bbd\u5ea6200px<br \/>\n      box.style.height &#061; &#039;200px&#039;;       \/\/ \u9ad8\u5ea6200px<br \/>\n      box.style.borderRadius &#061; &#039;10px&#039;;   \/\/ \u5706\u89d210px<br \/>\n      box.style.color &#061; &#039;white&#039;;        \/\/ \u6587\u5b57\u767d\u8272<br \/>\n      box.style.fontSize &#061; &#039;16px&#039;;      \/\/ \u5b57\u4f53\u5927\u5c0f16px<\/p>\n<p>      \/\/ 3. \u6e05\u7a7a\u5355\u4e2a\u6837\u5f0f&#xff08;\u8bbe\u4e3a\u7a7a\u5b57\u7b26\u4e32&#xff09;<br \/>\n      \/\/ box.style.border &#061; &#039;&#039;;<br \/>\n    }<br \/>\n  &lt;\/script&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p>\u5e38\u89c1\u6837\u5f0f\u5c5e\u6027&#xff1a;<\/p>\n<ul>\n<li>color: \u4fee\u6539\u6587\u672c\u989c\u8272<\/li>\n<li>backgroundColor: \u4fee\u6539\u80cc\u666f\u989c\u8272<\/li>\n<li>fontSize: \u4fee\u6539\u5b57\u4f53\u5927\u5c0f<\/li>\n<li>width\u00a0\/\u00a0height: \u4fee\u6539\u5143\u7d20\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6<\/li>\n<li>display: \u63a7\u5236\u5143\u7d20\u7684\u663e\u793a\u65b9\u5f0f&#xff08;\u5982\u00a0none\u00a0\u9690\u85cf\u5143\u7d20&#xff09;<\/li>\n<\/ul>\n<ul>\n<li>\u6ce8\u610f\u4e8b\u9879<\/li>\n<li>\u5c5e\u6027\u540d\u8f6c\u6362&#xff1a;CSS \u7684 font-size \u2192 JS \u7684 fontSize&#xff0c;border-top \u2192 borderTop&#xff0c;\u6240\u6709\u8fde\u5b57\u7b26\u8f6c\u9a7c\u5cf0&#xff1b;<br \/>\n\u5355\u4f4d\u5fc5\u987b\u52a0&#xff1a;\u6570\u5b57\u7c7b\u6837\u5f0f&#xff08;\u5bbd\u3001\u9ad8\u3001\u5b57\u4f53\u5927\u5c0f&#xff09;\u5fc5\u987b\u5e26\u5355\u4f4d&#xff08;px\/rem \u7b49&#xff09;&#xff0c;\u5426\u5219\u65e0\u6548&#xff1b;<br \/>\n\u4f18\u5148\u7ea7&#xff1a;style \u8bbe\u7f6e\u7684\u884c\u5185\u6837\u5f0f\u4f18\u5148\u7ea7\u9ad8\u4e8e CSS \u7c7b\u6837\u5f0f&#xff08;!important \u9664\u5916&#xff09;&#xff1b;<br \/>\n\u6e05\u7a7a\u6837\u5f0f&#xff1a;\u5c06\u6837\u5f0f\u503c\u8bbe\u4e3a\u7a7a\u5b57\u7b26\u4e32&#xff08;box.style.backgroundColor &#061; &#039;&#039;&#xff09;&#xff0c;\u4f1a\u6062\u590d\u4e3a CSS \u7c7b \/ \u9ed8\u8ba4\u6837\u5f0f<\/li>\n<\/ul>\n<h4>\u901a\u8fc7 JavaScript \u4fee\u6539\u6837\u5f0f<\/h4>\n<p>\u53ef\u4ee5\u901a\u8fc7 JavaScript \u83b7\u53d6 DOM \u5143\u7d20\u5e76\u76f4\u63a5\u4fee\u6539\u5176\u00a0style\u00a0\u5c5e\u6027<\/p>\n<p>const element &#061; document.getElementById(&#034;myElement&#034;);<br \/>\nelement.style.color &#061; &#034;red&#034;;<br \/>\nelement.style.fontSize &#061; &#034;16px&#034;;<\/p>\n<h2>\u83b7\u53d6\u8868\u5355\u91cc\u7684\u503c<\/h2>\n<p>\u65b9\u6cd5 1&#xff1a;\u901a\u8fc7\u5143\u7d20 ID \u76f4\u63a5\u83b7\u53d6&#xff08;\u6700\u7b80\u5355&#xff09;<br \/>\n\u8fd9\u662f\u6700\u76f4\u89c2\u7684\u65b9\u5f0f&#xff0c;\u7ed9\u8868\u5355\u5143\u7d20\u8bbe\u7f6e\u552f\u4e00 id&#xff0c;\u7136\u540e\u7528 document.getElementById() \u83b7\u53d6\u5143\u7d20&#xff0c;\u518d\u901a\u8fc7 .value \u5c5e\u6027\u62ff\u5230\u503c<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;body&gt;<br \/>\n  &lt;form&gt;<br \/>\n    &lt;label&gt;\u7528\u6237\u540d&#xff1a;&lt;\/label&gt;<br \/>\n    &lt;input type&#061;&#034;text&#034; id&#061;&#034;username&#034;&gt;&lt;br&gt;<\/p>\n<p>    &lt;label&gt;\u5bc6\u7801&#xff1a;&lt;\/label&gt;<br \/>\n    &lt;input type&#061;&#034;password&#034; id&#061;&#034;password&#034;&gt;&lt;br&gt;<\/p>\n<p>    &lt;label&gt;\u6027\u522b&#xff1a;&lt;\/label&gt;<br \/>\n    &lt;input type&#061;&#034;radio&#034; name&#061;&#034;gender&#034; id&#061;&#034;male&#034; value&#061;&#034;\u7537&#034;&gt;\u7537<br \/>\n    &lt;input type&#061;&#034;radio&#034; name&#061;&#034;gender&#034; id&#061;&#034;female&#034; value&#061;&#034;\u5973&#034;&gt;\u5973&lt;br&gt;<\/p>\n<p>    &lt;button type&#061;&#034;button&#034; onclick&#061;&#034;getFormValueById()&#034;&gt;\u83b7\u53d6\u503c&lt;\/button&gt;<br \/>\n  &lt;\/form&gt;<\/p>\n<p>  &lt;script&gt;<br \/>\n    function getFormValueById() {<br \/>\n      \/\/ \u83b7\u53d6\u8f93\u5165\u6846\u3001\u5bc6\u7801\u6846\u7684\u503c<br \/>\n      const username &#061; document.getElementById(&#039;username&#039;).value;<br \/>\n      const password &#061; document.getElementById(&#039;password&#039;).value;<\/p>\n<p>      \/\/ \u83b7\u53d6\u5355\u9009\u6846\u7684\u503c&#xff08;\u9700\u8981\u5224\u65ad\u54ea\u4e2a\u88ab\u9009\u4e2d&#xff09;<br \/>\n      const male &#061; document.getElementById(&#039;male&#039;);<br \/>\n      const female &#061; document.getElementById(&#039;female&#039;);<br \/>\n      const gender &#061; male.checked ? male.value : female.checked ? female.value : &#039;\u672a\u9009\u62e9&#039;;<\/p>\n<p>      \/\/ \u6253\u5370\u7ed3\u679c<br \/>\n      console.log(&#039;\u7528\u6237\u540d&#xff1a;&#039;, username);<br \/>\n      console.log(&#039;\u5bc6\u7801&#xff1a;&#039;, password);<br \/>\n      console.log(&#039;\u6027\u522b&#xff1a;&#039;, gender);<br \/>\n    }<br \/>\n  &lt;\/script&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<p>\u65b9\u6cd5 2&#xff1a;\u901a\u8fc7\u8868\u5355\u5bf9\u8c61\u83b7\u53d6&#xff08;\u66f4\u89c4\u8303&#xff09;<\/p>\n<p>\u5148\u83b7\u53d6\u6574\u4e2a\u8868\u5355\u5bf9\u8c61&#xff0c;\u518d\u901a\u8fc7\u5143\u7d20\u7684 name \u5c5e\u6027&#xff08;\u8868\u5355\u5143\u7d20\u7684\u6838\u5fc3\u6807\u8bc6&#xff09;\u83b7\u53d6\u5bf9\u5e94\u7684\u503c&#xff0c;\u9002\u5408\u8868\u5355\u5143\u7d20\u8f83\u591a\u7684\u573a\u666f\u3002<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;body&gt;<br \/>\n  &lt;form id&#061;&#034;userForm&#034;&gt;<br \/>\n    &lt;label&gt;\u7528\u6237\u540d&#xff1a;&lt;\/label&gt;<br \/>\n    &lt;input type&#061;&#034;text&#034; name&#061;&#034;username&#034;&gt;&lt;br&gt;<\/p>\n<p>    &lt;label&gt;\u7231\u597d&#xff1a;&lt;\/label&gt;<br \/>\n    &lt;input type&#061;&#034;checkbox&#034; name&#061;&#034;hobby&#034; value&#061;&#034;\u8bfb\u4e66&#034;&gt;\u8bfb\u4e66<br \/>\n    &lt;input type&#061;&#034;checkbox&#034; name&#061;&#034;hobby&#034; value&#061;&#034;\u8fd0\u52a8&#034;&gt;\u8fd0\u52a8<br \/>\n    &lt;input type&#061;&#034;checkbox&#034; name&#061;&#034;hobby&#034; value&#061;&#034;\u6e38\u620f&#034;&gt;\u6e38\u620f&lt;br&gt;<\/p>\n<p>    &lt;label&gt;\u57ce\u5e02&#xff1a;&lt;\/label&gt;<br \/>\n    &lt;select name&#061;&#034;city&#034;&gt;<br \/>\n      &lt;option value&#061;&#034;&#034;&gt;\u8bf7\u9009\u62e9&lt;\/option&gt;<br \/>\n      &lt;option value&#061;&#034;\u5317\u4eac&#034;&gt;\u5317\u4eac&lt;\/option&gt;<br \/>\n      &lt;option value&#061;&#034;\u4e0a\u6d77&#034;&gt;\u4e0a\u6d77&lt;\/option&gt;<br \/>\n    &lt;\/select&gt;&lt;br&gt;<\/p>\n<p>    &lt;button type&#061;&#034;button&#034; onclick&#061;&#034;getFormValueByForm()&#034;&gt;\u83b7\u53d6\u503c&lt;\/button&gt;<br \/>\n  &lt;\/form&gt;<\/p>\n<p>  &lt;script&gt;<br \/>\n    function getFormValueByForm() {<br \/>\n      \/\/ \u83b7\u53d6\u8868\u5355\u5bf9\u8c61<br \/>\n      const form &#061; document.getElementById(&#039;userForm&#039;);<\/p>\n<p>      \/\/ \u83b7\u53d6\u666e\u901a\u8f93\u5165\u6846\u3001\u4e0b\u62c9\u6846\u7684\u503c&#xff08;\u901a\u8fc7name&#xff09;<br \/>\n      const username &#061; form.username.value;<br \/>\n      const city &#061; form.city.value;<\/p>\n<p>      \/\/ \u83b7\u53d6\u590d\u9009\u6846\u7684\u503c&#xff08;\u9700\u8981\u904d\u5386\u5224\u65ad\u9009\u4e2d\u72b6\u6001&#xff09;<br \/>\n      const hobbies &#061; [];<br \/>\n      form.hobby.forEach(item &#061;&gt; {<br \/>\n        if (item.checked) {<br \/>\n          hobbies.push(item.value);<br \/>\n        }<br \/>\n      });<\/p>\n<p>      console.log(&#039;\u7528\u6237\u540d&#xff1a;&#039;, username);<br \/>\n      console.log(&#039;\u57ce\u5e02&#xff1a;&#039;, city);<br \/>\n      console.log(&#039;\u7231\u597d&#xff1a;&#039;, hobbies);<br \/>\n    }<br \/>\n  &lt;\/script&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<h2>H5\u81ea\u5b9a\u4e49\u5c5e\u6027-data<\/h2>\n<h3>\u4e00\u3001\u5982\u4f55\u5b9a\u4e49 data-* \u81ea\u5b9a\u4e49\u5c5e\u6027<\/h3>\n<p>\n\u81ea\u5b9a\u4e49\u5c5e\u6027\u5fc5\u987b\u4ee5 data- \u4e3a\u524d\u7f00&#xff0c;\u540e\u9762\u53ef\u4ee5\u8ddf\u4efb\u610f\u540d\u79f0&#xff08;\u5efa\u8bae\u5c0f\u5199\u3001\u7528\u8fde\u5b57\u7b26\u5206\u9694&#xff09;&#xff0c;\u76f4\u63a5\u5199\u5728 HTML \u5143\u7d20\u6807\u7b7e\u91cc\u5373\u53ef\u3002<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;body&gt;<br \/>\n  &lt;!&#8211; \u5355\u4e2a\u81ea\u5b9a\u4e49\u5c5e\u6027 &#8211;&gt;<br \/>\n  &lt;div id&#061;&#034;user&#034; data-id&#061;&#034;1001&#034;&gt;\u7528\u6237\u4fe1\u606f&lt;\/div&gt;<\/p>\n<p>  &lt;!&#8211; \u591a\u4e2a\u81ea\u5b9a\u4e49\u5c5e\u6027 &#8211;&gt;<br \/>\n  &lt;ul&gt;<br \/>\n    &lt;li data-product-id&#061;&#034;888&#034; data-product-name&#061;&#034;\u624b\u673a&#034; data-price&#061;&#034;2999&#034;&gt;\u667a\u80fd\u624b\u673a&lt;\/li&gt;<br \/>\n    &lt;li data-product-id&#061;&#034;999&#034; data-product-name&#061;&#034;\u7535\u8111&#034; data-price&#061;&#034;5999&#034;&gt;\u7b14\u8bb0\u672c\u7535\u8111&lt;\/li&gt;<br \/>\n  &lt;\/ul&gt;<\/p>\n<p>  &lt;!&#8211; \u5e26\u8fde\u5b57\u7b26\u7684\u81ea\u5b9a\u4e49\u5c5e\u6027&#xff08;\u63a8\u8350\u547d\u540d\u65b9\u5f0f&#xff09; &#8211;&gt;<br \/>\n  &lt;button data-user-status&#061;&#034;active&#034; data-user-role&#061;&#034;admin&#034;&gt;\u64cd\u4f5c\u6309\u94ae&lt;\/button&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<h4>\u4e8c\u3001\u5728 JavaScript \u4e2d\u64cd\u4f5c\u81ea\u5b9a\u4e49\u5c5e\u6027<\/h4>\n<p>\u6709\u4e24\u79cd\u4e3b\u6d41\u65b9\u5f0f&#xff0c;\u63a8\u8350\u4f7f\u7528 dataset&#xff08;\u66f4\u7b80\u6d01\u3001\u7b26\u5408 H5 \u89c4\u8303&#xff09;\u3002<\/p>\n<p>\u65b9\u5f0f 1&#xff1a;\u4f7f\u7528 dataset&#xff08;\u63a8\u8350&#xff09;<\/p>\n<p>dataset \u662f HTML5 \u4e3a\u5143\u7d20\u65b0\u589e\u7684\u5c5e\u6027&#xff0c;\u4f1a\u81ea\u52a8\u6536\u96c6\u6240\u6709 data-* \u5c5e\u6027&#xff0c;\u5e76\u4e14&#xff1a;<\/p>\n<ul>\n<li>\u81ea\u52a8\u53bb\u6389 data- \u524d\u7f00<\/li>\n<li>\u5c06\u8fde\u5b57\u7b26\u547d\u540d&#xff08;\u5982 data-user-name&#xff09;\u8f6c\u4e3a\u9a7c\u5cf0\u547d\u540d&#xff08;userName&#xff09;\n<p>\u8be5\u56fe\u7d27\u63a5\u4e0a\u4e00\u5f20\u56fe<br \/>\n&lt;script&gt;<br \/>\n  \/\/ 1. \u83b7\u53d6\u5355\u4e2a\u5143\u7d20\u7684\u81ea\u5b9a\u4e49\u5c5e\u6027<br \/>\n  const userDiv &#061; document.getElementById(&#039;user&#039;);<br \/>\n  \/\/ \u83b7\u53d6 data-id<br \/>\n  console.log(userDiv.dataset.id); \/\/ \u8f93\u51fa&#xff1a;1001<\/p>\n<p>  \/\/ 2. \u83b7\u53d6\u5e26\u8fde\u5b57\u7b26\u7684\u81ea\u5b9a\u4e49\u5c5e\u6027&#xff08;\u81ea\u52a8\u8f6c\u9a7c\u5cf0&#xff09;<br \/>\n  const btn &#061; document.querySelector(&#039;button&#039;);<br \/>\n  console.log(btn.dataset.userStatus); \/\/ \u8f93\u51fa&#xff1a;active<br \/>\n  console.log(btn.dataset.userRole);   \/\/ \u8f93\u51fa&#xff1a;admin<\/p>\n<p>  \/\/ 3. \u8bbe\u7f6e\u81ea\u5b9a\u4e49\u5c5e\u6027<br \/>\n  userDiv.dataset.name &#061; &#039;\u5f20\u4e09&#039;; \/\/ \u76f8\u5f53\u4e8e\u6dfb\u52a0 data-name&#061;&#034;\u5f20\u4e09&#034;<br \/>\n  userDiv.dataset.age &#061; 25;     \/\/ \u76f8\u5f53\u4e8e\u6dfb\u52a0 data-age&#061;&#034;25&#034;<br \/>\n  console.log(userDiv.dataset.name); \/\/ \u8f93\u51fa&#xff1a;\u5f20\u4e09<\/p>\n<p>  \/\/ 4. \u904d\u5386\u6240\u6709\u81ea\u5b9a\u4e49\u5c5e\u6027<br \/>\n  const productLi &#061; document.querySelector(&#039;li&#039;);<br \/>\n  for (let key in productLi.dataset) {<br \/>\n    console.log(key &#043; &#039;: &#039; &#043; productLi.dataset[key]);<br \/>\n    \/\/ \u8f93\u51fa&#xff1a;productId: 888\u3001productName: \u624b\u673a\u3001price: 2999<br \/>\n  }<\/p>\n<p>  \/\/ 5. \u5220\u9664\u81ea\u5b9a\u4e49\u5c5e\u6027<br \/>\n  delete userDiv.dataset.age; \/\/ \u79fb\u9664 data-age \u5c5e\u6027<br \/>\n  console.log(userDiv.dataset.age); \/\/ \u8f93\u51fa&#xff1a;undefined<br \/>\n&lt;\/script&gt;<\/p>\n<h4>\u6ce8\u610f\u4e8b\u9879<\/h4>\n<\/li>\n<li>\u81ea\u5b9a\u4e49\u5c5e\u6027\u540d\u53ea\u80fd\u5305\u542b&#xff1a;\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u8fde\u5b57\u7b26&#xff08;-&#xff09;\u3001\u4e0b\u5212\u7ebf&#xff08;_&#xff09;\u3001\u70b9&#xff08;.&#xff09;\u3001\u5192\u53f7&#xff08;:&#xff09;&#xff0c;\u4e14\u4e0d\u80fd\u4ee5\u6570\u5b57\u5f00\u5934\u3002<\/li>\n<li>dataset \u8bfb\u53d6\u7684\u503c\u90fd\u662f\u5b57\u7b26\u4e32\u7c7b\u578b&#xff0c;\u5982\u679c\u662f\u6570\u5b57 \/ \u5e03\u5c14\u503c&#xff0c;\u9700\u8981\u624b\u52a8\u8f6c\u6362&#xff08;\u5982 Number(li.dataset.price)&#xff09;\u3002<\/li>\n<li>\u4e0d\u8981\u7528\u81ea\u5b9a\u4e49\u5c5e\u6027\u5b58\u50a8\u654f\u611f\u6570\u636e&#xff08;\u5982\u5bc6\u7801&#xff09;&#xff0c;\u56e0\u4e3a\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u63a7\u5236\u53f0\u76f4\u63a5\u770b\u5230<\/li>\n<\/ul>\n<h2>\u5b9a\u65f6\u5668&#8212;\u95f4\u6b47\u51fd\u6570<\/h2>\n<p>JavaScript \u63d0\u4f9b\u4e86\u4e24\u79cd\u6838\u5fc3\u5b9a\u65f6\u5668\u51fd\u6570&#xff0c;\u90fd\u5c5e\u4e8e window \u5bf9\u8c61&#xff08;\u6d4f\u89c8\u5668\u73af\u5883&#xff09;&#xff0c;\u5206\u522b\u7528\u4e8e\u4e00\u6b21\u6027\u5ef6\u65f6\u6267\u884c\u548c\u5468\u671f\u6027\u91cd\u590d\u6267\u884c<\/p>\n<h5>1. setTimeout ()&#xff1a;\u4e00\u6b21\u6027\u5ef6\u65f6\u6267\u884c<\/h5>\n<p>setTimeout() \u7528\u4e8e\u6307\u5b9a\u4e00\u6bb5\u65f6\u95f4\u540e\u6267\u884c\u4e00\u6b21\u67d0\u4e2a\u51fd\u6570 \/ \u4ee3\u7801&#xff0c;\u6267\u884c\u540e\u5b9a\u65f6\u5668\u81ea\u52a8\u5931\u6548<\/p>\n<p>\u8bed\u6cd5&#xff1a;<\/p>\n<p>\/\/ \u57fa\u7840\u8bed\u6cd5<br \/>\nlet timerId &#061; setTimeout(callback, delay, param1, param2, &#8230;);<\/p>\n<p>callback&#xff1a;\u5ef6\u65f6\u540e\u8981\u6267\u884c\u7684\u51fd\u6570 \/ \u4ee3\u7801\u5b57\u7b26\u4e32&#xff08;\u4e0d\u63a8\u8350\u5b57\u7b26\u4e32&#xff09;<br \/>\ndelay&#xff1a;\u5ef6\u65f6\u65f6\u95f4&#xff08;\u6beb\u79d2&#xff0c;1 \u79d2 &#061; 1000 \u6beb\u79d2&#xff09;&#xff0c;\u6700\u5c0f\u7ea6 4ms&#xff08;\u6d4f\u89c8\u5668\u9650\u5236&#xff09;<br \/>\nparam1&#8230;&#xff1a;\u4f20\u7ed9\u56de\u8c03\u51fd\u6570\u7684\u53c2\u6570&#xff08;\u53ef\u9009&#xff09;<br \/>\ntimerId&#xff1a;\u5b9a\u65f6\u5668\u552f\u4e00\u6807\u8bc6&#xff08;\u6570\u5b57&#xff09;&#xff0c;\u7528\u4e8e\u540e\u7eed\u505c\u6b62\u5b9a\u65f6\u5668<\/p>\n<p>\u793a\u4f8b\u4ee3\u7801<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;body&gt;<br \/>\n  &lt;button onclick&#061;&#034;stopMyTimeout()&#034;&gt;\u505c\u6b62\u5ef6\u65f6\u4efb\u52a1&lt;\/button&gt;<\/p>\n<p>  &lt;script&gt;<br \/>\n    \/\/ \u793a\u4f8b1&#xff1a;\u57fa\u7840\u7528\u6cd5&#xff08;3\u79d2\u540e\u6267\u884c&#xff09;<br \/>\n    const timer1 &#061; setTimeout(() &#061;&gt; {<br \/>\n      alert(&#039;3\u79d2\u5230\u4e86&#xff01;&#039;);<br \/>\n    }, 3000);<\/p>\n<p>    \/\/ \u793a\u4f8b2&#xff1a;\u5e26\u53c2\u6570\u7684\u56de\u8c03\u51fd\u6570<br \/>\n    const timer2 &#061; setTimeout((name, age) &#061;&gt; {<br \/>\n      console.log(&#096;\u4f60\u597d${name}&#xff0c;\u5e74\u9f84${age}&#096;); \/\/ \u8f93\u51fa&#xff1a;\u4f60\u597d\u5f20\u4e09&#xff0c;\u5e74\u9f8425<br \/>\n    }, 2000, &#039;\u5f20\u4e09&#039;, 25);<\/p>\n<p>    \/\/ \u505c\u6b62\u5ef6\u65f6\u4efb\u52a1<br \/>\n    function stopMyTimeout() {<br \/>\n      clearTimeout(timer1); \/\/ \u6e05\u9664timer1&#xff0c;alert\u4e0d\u4f1a\u5f39\u51fa<br \/>\n      console.log(&#039;\u5ef6\u65f6\u4efb\u52a1\u5df2\u505c\u6b62&#039;);<br \/>\n    }<br \/>\n  &lt;\/script&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<h3>2. setInterval ()&#xff1a;\u5468\u671f\u6027\u91cd\u590d\u6267\u884c<\/h3>\n<p>\nsetInterval() \u7528\u4e8e\u6bcf\u9694\u6307\u5b9a\u65f6\u95f4\u91cd\u590d\u6267\u884c\u67d0\u4e2a\u51fd\u6570 \/ \u4ee3\u7801&#xff0c;\u76f4\u5230\u624b\u52a8\u505c\u6b62<\/p>\n<p>\u8bed\u6cd5&#xff1a;<\/p>\n<p>let intervalId &#061; setInterval(callback, delay, param1, param2, &#8230;);<\/p>\n<p>\u53c2\u6570\u542b\u4e49\u548c setTimeout() \u4e00\u81f4&#xff0c;\u533a\u522b\u662f callback \u4f1a\u91cd\u590d\u6267\u884c<\/p>\n<p>\u793a\u4f8b\u4ee3\u7801&#xff1a;<\/p>\n<p>&lt;!DOCTYPE html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;body&gt;<br \/>\n  &lt;p&gt;\u5012\u8ba1\u65f6&#xff1a;&lt;span id&#061;&#034;count&#034;&gt;10&lt;\/span&gt; \u79d2&lt;\/p&gt;<br \/>\n  &lt;button onclick&#061;&#034;stopMyInterval()&#034;&gt;\u505c\u6b62\u5012\u8ba1\u65f6&lt;\/button&gt;<\/p>\n<p>  &lt;script&gt;<br \/>\n    let count &#061; 10;<br \/>\n    const countSpan &#061; document.getElementById(&#039;count&#039;);<\/p>\n<p>    \/\/ \u793a\u4f8b&#xff1a;\u6bcf\u79d2\u6267\u884c\u4e00\u6b21\u5012\u8ba1\u65f6<br \/>\n    const intervalId &#061; setInterval(() &#061;&gt; {<br \/>\n      count&#8211;;<br \/>\n      countSpan.textContent &#061; count;<\/p>\n<p>      \/\/ \u5012\u8ba1\u65f6\u7ed3\u675f\u540e\u81ea\u52a8\u505c\u6b62<br \/>\n      if (count &lt;&#061; 0) {<br \/>\n        clearInterval(intervalId);<br \/>\n        alert(&#039;\u5012\u8ba1\u65f6\u7ed3\u675f&#xff01;&#039;);<br \/>\n      }<br \/>\n    }, 1000);<\/p>\n<p>    \/\/ \u624b\u52a8\u505c\u6b62\u5468\u671f\u6027\u4efb\u52a1<br \/>\n    function stopMyInterval() {<br \/>\n      clearInterval(intervalId);<br \/>\n      countSpan.textContent &#061; &#039;\u5df2\u505c\u6b62&#039;;<br \/>\n    }<br \/>\n  &lt;\/script&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<\/p>\n<h3>\u4e8c\u3001\u5173\u952e\u6ce8\u610f\u4e8b\u9879<\/h3>\n<h5>\n1. \u5b9a\u65f6\u5668\u7684 \u201c\u5f02\u6b65\u7279\u6027\u201d<\/h5>\n<p>\nJavaScript \u662f\u5355\u7ebf\u7a0b\u7684&#xff0c;\u5b9a\u65f6\u5668\u7684 delay \u4e0d\u662f \u201c\u7edd\u5bf9\u6267\u884c\u65f6\u95f4\u201d&#xff0c;\u800c\u662f \u201c\u6700\u65e9\u6267\u884c\u65f6\u95f4\u201d\u2014\u2014 \u5982\u679c\u4e3b\u7ebf\u7a0b\u6709\u8017\u65f6\u4efb\u52a1&#xff08;\u5982\u590d\u6742\u8ba1\u7b97&#xff09;&#xff0c;\u5b9a\u65f6\u5668\u4f1a\u7b49\u5f85\u4e3b\u7ebf\u7a0b\u7a7a\u95f2\u540e\u624d\u6267\u884c<\/p>\n<p>\u793a\u4f8b&#xff1a;<\/p>\n<p>\/\/ \u770b\u4f3c1\u79d2\u540e\u6267\u884c&#xff0c;\u4f46\u5b9e\u9645\u4f1a\u7b495\u79d2&#xff08;\u56e0\u4e3aalert\u963b\u585e\u4e86\u4e3b\u7ebf\u7a0b&#xff09;<br \/>\nsetTimeout(() &#061;&gt; {<br \/>\n  console.log(&#039;1\u79d2\u5230\u4e86&#xff1f;&#039;);<br \/>\n}, 1000);<\/p>\n<p>\/\/ \u963b\u585e\u4e3b\u7ebf\u7a0b5\u79d2<br \/>\nalert(&#039;\u8bf7\u7b49\u5f855\u79d2\u540e\u5173\u95ed&#039;);<\/p>\n<h5>2. \u6e05\u9664\u5b9a\u65f6\u5668\u7684\u91cd\u8981\u6027<\/h5>\n<ul>\n<li>\u9875\u9762\u5378\u8f7d \/ \u7ec4\u4ef6\u9500\u6bc1\u524d&#xff0c;\u5fc5\u987b\u6e05\u9664\u672a\u6267\u884c\u7684\u5b9a\u65f6\u5668&#xff0c;\u5426\u5219\u4f1a\u5bfc\u81f4\u5185\u5b58\u6cc4\u6f0f\u3001\u65e0\u6548\u4ee3\u7801\u6267\u884c&#xff08;\u6bd4\u5982\u9875\u9762\u8df3\u8f6c\u540e\u5b9a\u65f6\u5668\u8fd8\u5728\u8dd1&#xff09;\u3002<\/li>\n<li>\u6e05\u9664\u5b9a\u65f6\u5668\u7684\u524d\u63d0&#xff1a;\u5fc5\u987b\u4fdd\u5b58 timerId&#xff08;\u4e0d\u80fd\u7528\u533f\u540d\u53d8\u91cf&#xff09;<\/li>\n<\/ul>\n<p>\u9519\u8bef\u793a\u4f8b&#xff1a;<\/p>\n<p>\/\/ \u9519\u8bef&#xff1a;timerId\u662f\u533f\u540d\u7684&#xff0c;\u65e0\u6cd5\u6e05\u9664<br \/>\nsetTimeout(() &#061;&gt; {}, 1000);<br \/>\n\/\/ \u6b63\u786e&#xff1a;\u4fdd\u5b58timerId<br \/>\nconst timerId &#061; setTimeout(() &#061;&gt; {}, 1000);<br \/>\nclearTimeout(timerId);<\/p>\n<p>\u603b\u7ed3&#xff1a;setTimeout&#xff1a;\u5ef6\u65f6\u4e00\u6b21\u6267\u884c&#xff0c;\u7528 clearTimeout(timerId) \u505c\u6b62&#xff0c;\u9002\u5408\u5355\u6b21\u5ef6\u65f6\u4efb\u52a1&#xff1b;<br \/>\nsetInterval&#xff1a;\u5468\u671f\u6027\u91cd\u590d\u6267\u884c&#xff0c;\u7528 clearInterval(intervalId) \u505c\u6b62&#xff0c;\u9002\u5408\u8f6e\u8be2 \/ \u5012\u8ba1\u65f6&#xff1b;<br \/>\n\u6838\u5fc3\u8981\u70b9&#xff1a;\u5b9a\u65f6\u5668\u662f\u5f02\u6b65\u7684&#xff0c;delay \u662f \u201c\u6700\u5c0f\u5ef6\u65f6\u201d&#xff1b;\u5fc5\u987b\u4fdd\u5b58 timerId \u624d\u80fd\u6e05\u9664&#xff0c;\u907f\u514d\u5185\u5b58\u6cc4\u6f0f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u5173\u53d8\u91cf\u7684\u58f0\u660e\u53d8\u91cf\u7684\u58f0\u660e\u6709\u51e0\u79cd\u65b9\u5f0f&#xff0c;\u4f8b\u5982\u7528let&#xff0c;const\u3002\u5728\u4ee5\u524d\u7684\u7248\u672c\u8fd8\u7528var\u6765\u58f0\u660evar\u7684\u7279\u70b9&#xff1a;1\u3001\u5141\u8bb8\u91cd\u590d\u58f0\u660e\u00a0 2\u3001\u5b58\u5728\u53d8\u91cf\u63d0\u5347&#xff0c;\u5373\u53d8\u91cf\u53ef\u4ee5\u518d\u58f0\u660e\u524d\u4f7f\u7528\u7f3a\u70b9&#xff1a;1\u3001var \u58f0\u660e\u7684\u53d8\u91cf\u4f1a\u88ab\u63d0\u5347\u5230\u51fd\u6570\u6216\u5168\u5c40\u4f5c\u7528\u57df\u7684\u9876\u90e8&#xff0c;\u5bfc\u81f4\u53d8\u91cf\u5728\u58f0\u660e\u524d\u5c31\u53ef\u4ee5\u8bbf\u95ee&#xff0c;\u4f46\u503c\u4e3a undefined\u3002\u8fd9\u79cd\u884c\u4e3a\u5bb9\u6613\u5f15\u53d1\u903b\u8f91\u9519\u8bef2\u3001var \u7684\u4f5c\u7528\u57df\u4ec5\u9650\u4e8e\u51fd\u6570\u6216\u5168\u5c40&#xff0c;\u800c\u975e\u5757\u7ea7&#xff08;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[187,87,190],"topic":[],"class_list":["post-77149","post","type-post","status-publish","format-standard","hentry","category-server","tag-javascript","tag-87","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>web APIS Day1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/77149.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"web APIS Day1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6709\u5173\u53d8\u91cf\u7684\u58f0\u660e\u53d8\u91cf\u7684\u58f0\u660e\u6709\u51e0\u79cd\u65b9\u5f0f&#xff0c;\u4f8b\u5982\u7528let&#xff0c;const\u3002\u5728\u4ee5\u524d\u7684\u7248\u672c\u8fd8\u7528var\u6765\u58f0\u660evar\u7684\u7279\u70b9&#xff1a;1\u3001\u5141\u8bb8\u91cd\u590d\u58f0\u660e\u00a0 2\u3001\u5b58\u5728\u53d8\u91cf\u63d0\u5347&#xff0c;\u5373\u53d8\u91cf\u53ef\u4ee5\u518d\u58f0\u660e\u524d\u4f7f\u7528\u7f3a\u70b9&#xff1a;1\u3001var \u58f0\u660e\u7684\u53d8\u91cf\u4f1a\u88ab\u63d0\u5347\u5230\u51fd\u6570\u6216\u5168\u5c40\u4f5c\u7528\u57df\u7684\u9876\u90e8&#xff0c;\u5bfc\u81f4\u53d8\u91cf\u5728\u58f0\u660e\u524d\u5c31\u53ef\u4ee5\u8bbf\u95ee&#xff0c;\u4f46\u503c\u4e3a undefined\u3002\u8fd9\u79cd\u884c\u4e3a\u5bb9\u6613\u5f15\u53d1\u903b\u8f91\u9519\u8bef2\u3001var \u7684\u4f5c\u7528\u57df\u4ec5\u9650\u4e8e\u51fd\u6570\u6216\u5168\u5c40&#xff0c;\u800c\u975e\u5757\u7ea7&#xff08;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/77149.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-23T17:50:16+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/77149.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/77149.html\",\"name\":\"web APIS Day1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-23T17:50:16+00:00\",\"dateModified\":\"2026-02-23T17:50:16+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/77149.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/77149.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/77149.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"web APIS Day1\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"web APIS Day1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/77149.html","og_locale":"zh_CN","og_type":"article","og_title":"web APIS Day1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6709\u5173\u53d8\u91cf\u7684\u58f0\u660e\u53d8\u91cf\u7684\u58f0\u660e\u6709\u51e0\u79cd\u65b9\u5f0f&#xff0c;\u4f8b\u5982\u7528let&#xff0c;const\u3002\u5728\u4ee5\u524d\u7684\u7248\u672c\u8fd8\u7528var\u6765\u58f0\u660evar\u7684\u7279\u70b9&#xff1a;1\u3001\u5141\u8bb8\u91cd\u590d\u58f0\u660e\u00a0 2\u3001\u5b58\u5728\u53d8\u91cf\u63d0\u5347&#xff0c;\u5373\u53d8\u91cf\u53ef\u4ee5\u518d\u58f0\u660e\u524d\u4f7f\u7528\u7f3a\u70b9&#xff1a;1\u3001var \u58f0\u660e\u7684\u53d8\u91cf\u4f1a\u88ab\u63d0\u5347\u5230\u51fd\u6570\u6216\u5168\u5c40\u4f5c\u7528\u57df\u7684\u9876\u90e8&#xff0c;\u5bfc\u81f4\u53d8\u91cf\u5728\u58f0\u660e\u524d\u5c31\u53ef\u4ee5\u8bbf\u95ee&#xff0c;\u4f46\u503c\u4e3a undefined\u3002\u8fd9\u79cd\u884c\u4e3a\u5bb9\u6613\u5f15\u53d1\u903b\u8f91\u9519\u8bef2\u3001var \u7684\u4f5c\u7528\u57df\u4ec5\u9650\u4e8e\u51fd\u6570\u6216\u5168\u5c40&#xff0c;\u800c\u975e\u5757\u7ea7&#xff08;","og_url":"https:\/\/www.wsisp.com\/helps\/77149.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-23T17:50:16+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/77149.html","url":"https:\/\/www.wsisp.com\/helps\/77149.html","name":"web APIS Day1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-23T17:50:16+00:00","dateModified":"2026-02-23T17:50:16+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/77149.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/77149.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/77149.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"web APIS Day1"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/77149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=77149"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/77149\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=77149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=77149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=77149"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=77149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}