{"id":9747,"date":"2020-12-25T00:44:12","date_gmt":"2020-12-24T16:44:12","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9747"},"modified":"2020-12-25T00:44:12","modified_gmt":"2020-12-24T16:44:12","slug":"dom-api-diff","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2020\/12\/dom-api-diff\/","title":{"rendered":"\u51e0\u4e2a\u5e38\u89c1\u529f\u80fd\u91cd\u5408DOM API\u7684\u7ec6\u8282\u5dee\u5f02"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9747\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=9747<\/a><br \/>\n\u672c\u6587\u6b22\u8fce\u5206\u4eab\u4e0e\u805a\u5408\uff0c\u5168\u6587\u8f6c\u8f7d\u5c31\u4e0d\u5fc5\u4e86\uff0c\u5c0a\u91cd\u7248\u6743\uff0c\u5708\u5b50\u5c31\u8fd9\u4e48\u5927\uff0c\u82e5\u6025\u7528\u53ef\u4ee5\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<p><script>window.wxShareImgUrl = 'https:\/\/www.zhangxinxu.com\/study\/image\/share\/202012-dom-api-diff.png';<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202012\/dom-api-diff-cover.png\" width=\"480\" height=\"309\" alt=\"\u5723\u8bde\u8282\u5feb\u4e50\" class=\"alignright thumb clip size-medium\" \/><\/p>\n<p>JS DOM API\u4e2d\u6709\u90e8\u5206API\u529f\u80fd\u662f\u53ef\u4ee5\u76f8\u4e92\u66ff\u4ee3\u7684\uff0c\u5b9e\u9645\u4e0a\uff0c\u5176\u662f\u6709\u7ec6\u8282\u5dee\u5f02\u7684\u3002<\/p>\n<p>\u8bf4\u660e\uff1a\u672c\u6587\u7684\u8fd9\u4e9b\u5dee\u5f02\u5bf9\u6bd4\u5747\u4e0d\u8003\u8651\u517c\u5bb9\u6027\u5dee\u5f02\u3002<\/p>\n<h3>\u4e00\u3001innerText\u5bf9\u6bd4textContent<\/h3>\n<p>\u8fd9\u4e2a\u4e4b\u524d\u4e13\u95e8\u5199\u6587\u7ae0\u4ecb\u7ecd\u8fc7\uff0c\u8be6\u89c1\uff1a\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/2019\/09\/js-dom-innertext-textcontent\/\">JS DOM innerText\u548ctextContent\u7684\u533a\u522b<\/a>\u201d\u3002<\/p>\n<p>\u5927\u81f4\u603b\u7ed3\u4e0b\u5c31\u662f\uff1a<\/p>\n<ol>\n<li><code>innerText<\/code>\u83b7\u53d6\u7684\u6587\u5b57\u7684\u6362\u884c\u7b26\u4f9d\u7136\u4fdd\u7559\uff1b<\/li>\n<li><code>innerText<\/code>\u65e0\u6cd5\u83b7\u53d6\u9690\u85cf\u6587\u5b57\uff1b<\/li>\n<li><code>innerText<\/code>\u6027\u80fd\u8981\u76f8\u5bf9\u5dee\u4e00\u4e9b\uff1b<\/li>\n<\/ol>\n<p>\u5177\u4f53\u6d4b\u8bd5\u53ef\u4ee5\u53c2\u89c1\u4e0a\u9762\u90a3\u7bc7\u6587\u7ae0\uff0c\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n<h3>\u4e8c\u3001getAttribute\u5bf9\u6bd4dataset\u5bf9\u8c61<\/h3>\n<p>\u4f8b\u5982\uff0c\u6709\u5982\u4e0bHTML\uff1a<\/p>\n<pre>&lt;button id=\"button\" data-author=\"zhangxinxu\"&gt;\u4f5c\u8005\u662f\u8c01\uff1f&lt;\/button&gt;<\/pre>\n<p>\u4f7f\u7528<code>getAttribute<\/code>\u548c<code>dataset<\/code>\u5bf9\u8c61\u90fd\u80fd\u83b7\u53d6<code>data-author<\/code>\u5c5e\u6027\u503c\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1azhangxinxu<\/span>\r\nbutton.getAttribute('data-author');<\/pre>\n<pre><span style=\"color:green;\">\/\/ \u7ed3\u679c\u4e5f\u662f\uff1azhangxinxu<\/span>\r\nbutton.dataset.author;<\/pre>\n<p>\u5982\u679c\u60a8\u5bf9dataset\u5bf9\u8c61\u6709\u4e9b\u964c\u751f\uff0c\u53ef\u4ee5\u53c2\u8003\u6211\u5dee\u4e0d\u591a10\u5e74\u524d\u5199\u7684\u8fd9\u7bc7\u6587\u7ae0\uff1a\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=1693\">HTML5\u81ea\u5b9a\u4e49\u5c5e\u6027\u5bf9\u8c61Dataset\u7b80\u4ecb<\/a>\u201d\u3002<\/p>\n<p>\u4e4d\u4e00\u770b\uff0c\u5728\u83b7\u53d6<code>data-*<\/code>\u81ea\u5b9a\u4e49\u5c5e\u6027\u7684\u573a\u666f\u4e0b\uff0c<code>getAttribute<\/code>\u548c<code>dataset<\/code>\u5bf9\u8c61\u4f3c\u4e4e\u53ef\u4ee5\u7b49\u540c\u3002<\/p>\n<p>\u5b9e\u9645\u4e0a\uff0c\u4e24\u8005\u8fd8\u662f\u6709\u5dee\u5f02\u7684\u3002<\/p>\n<p>\u5dee\u522b\u5728\u4e8e\u5927\u5c0f\u5199\u654f\u611f\u7684\u533a\u522b\uff0c<code>getAttribute<\/code>\u65b9\u6cd5\u662f\u65e0\u89c6\u5927\u5c0f\u5199\u7684\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;button id=\"button\" data-AUTHOR=\"zhangxinxu\"&gt;\u4f5c\u8005\u662f\u8c01\uff1f&lt;\/button&gt;<\/pre>\n<pre><span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1azhangxinxu<\/span>\r\nbutton.getAttribute('DATA-author');<\/pre>\n<pre><span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1aundefined<\/span>\r\nbutton.dataset.AUTHOR;<\/pre>\n<p>\u622a\u56fe\u793a\u610f\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202012\/2020-12-24_234638.png\" width=\"583\" height=\"157\" alt=\"console\u8f93\u51fa\u622a\u56fe\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5728\u672c\u4f8b\u4e2d\uff0c\u8981\u60f3dataset\u5bf9\u8c61\u6b63\u786e\u83b7\u53d6<code>data-AUTHOR<\/code>\u5c5e\u6027\u503c\uff0c\u9700\u8981\u4f7f\u7528\u5c0f\u5199\uff1a<\/p>\n<pre><span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1azhangxinxu<\/span>\r\nbutton.dataset.author;<\/pre>\n<p>\u5982\u679c\u81ea\u5b9a\u4e49\u5c5e\u6027\u5305\u542b\u591a\u4e2a\u8bcd\u7ec4\uff0c\u5219dataset\u5bf9\u8c61\u5c5e\u6027\u503c\u9700\u8981\u4f7f\u7528\u9a7c\u5cf0\u547d\u540d\u83b7\u53d6\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;button id=\"button\" data-article-author=\"zhangxinxu\"&gt;\u611f\u8c22\u9605\u8bfb\uff01&lt;\/button&gt;<\/pre>\n<pre><span style=\"color:green;\">\/\/ \u7ed3\u679c\u90fd\u662f\uff1azhangxinxu<\/span>\r\nbutton.getAttribute('data-article-author');\r\nbutton.dataset.articleAuthor;<\/pre>\n<p>\u4e14\u53ea\u80fd\u4f7f\u7528\u9a7c\u5cf0\u547d\u540d\u65b9\u6cd5\uff0c\u4f8b\u5982\u4e0b\u9762\u7684\u8bed\u53e5\u8fd8\u662f\u8fd4\u56de<code>undefined<\/code>\uff1a<\/p>\n<pre><span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1aundefined<\/span>\r\nbutton.dataset['article-author'];<\/pre>\n<p>\u8fd0\u884c\u7ed3\u679c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202012\/2020-12-24_235346.png\" width=\"573\" height=\"153\" alt=\"\u591a\u4e2a\u81ea\u5b9a\u4e49\u5c5e\u6027\u5b57\u6bb5\u8fd0\u884c\u7ed3\u679c\" class=\"alignnone size-medium\" \/><\/p>\n<h3>\u4e09\u3001getElementById\u5bf9\u6bd4querySelector<\/h3>\n<p>\u5df2\u77e5\u4e00\u4e2a\u5143\u7d20\u7684ID\u662f<code>'thanksForShare'<\/code>\uff0c\u5219\u4e0b\u9762\u4e24\u884cDOM API\u7684\u4f7f\u7528\u6700\u540e\u8fd4\u56de\u7684\u7ed3\u679c\u662f\u4e00\u6837\u7684\uff1a<\/p>\n<pre><span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1atrue<\/span>\r\ndocument.getElementById('thanksForShare') === document.querySelector('#thanksForShare')<\/pre>\n<p>Chrome\u63a7\u5236\u53f0\u8dd1\u4e00\u4e0b\uff0c\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202012\/2020-12-25_000327.png\" width=\"381\" height=\"148\" alt=\"DOM\u5143\u7d20\u83b7\u53d6\u76f8\u7b49\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u8fd9\u4e48\u4e00\u770b\uff0c\u5bf9\u4e8e\u901a\u8fc7ID\u9009\u62e9\u5668\u83b7\u53d6\u5143\u7d20\u4e0a\uff0c<code>getElementById<\/code>\u548c<code>querySelector<\/code>\u65b9\u6cd5\u4f3c\u4e4e\u662f\u7b49\u6548\u7684\uff0c\u7a76\u7adf\u7528\u54ea\u4e2a\u76f4\u63a5\u770b\u5fc3\u60c5\u5c31\u597d\u4e86\uff0c\u662f\u8fd9\u6837\u7684\u5417\uff1f<\/p>\n<p>\u5b9e\u9645\u4e0a\u4e0d\u662f\u7684\uff0c\u63a8\u8350\u4f7f\u7528<code>getElementById()<\/code>\u65b9\u6cd5\uff0c\u56e0\u4e3a\u8fd9\u4e2aAPI\u7684\u5bb9\u9519\u6027\u6700\u5f3a\uff0c\u4e0d\u5bb9\u6613\u5bfc\u81f4JS\u8fd0\u884c\u4e2d\u65ad\u3002<\/p>\n<p>\u5047\u8bbe\u67d0\u4e2a\u5143\u7d20\u7684ID\u662f\u672a\u77e5\u7684\uff0c\u901a\u8fc7\u53c2\u6570\u4f20\u8fc7\u6765\u7684\uff0c\u4f46\u662f\u8fd9\u4e2a\u5b57\u7b26\u4e32\u53c2\u6570\u53ef\u80fd\u5404\u79cd\u5404\u6837\uff0c\u5047\u8bbe\u8fd9\u4e2a\u5b57\u7b26\u4e32\u662f<code>'thanksForShare!'<\/code>\uff0c\u6b64\u65f6\u5206\u522b\u8fd0\u884c\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n<pre><span style=\"color:green;\">\/\/ \u7ed3\u679c\u662f\uff1f<\/span>\r\ndocument.getElementById('thanksForShare!');\r\ndocument.querySelector('#thanksForShare!');<\/pre>\n<p>\u7ed3\u679c<code>getElementById()<\/code>\u65b9\u6cd5\u5b89\u5168\u5730\u8fd4\u56de\u4e86<code>null<\/code>\uff0c\u4f46\u662f<code>querySelector()<\/code>\u65b9\u6cd5\u76f4\u63a5\u62a5\u9519\u4e86\uff1a<\/p>\n<blockquote><p>VM309:1 Uncaught DOMException: Failed to execute &#8216;querySelector&#8217; on &#8216;Document&#8217;: &#8216;#thanksForShare!&#8217; is not a valid selector.<\/p><\/blockquote>\n<p>\u773c\u89c1\u4e3a\u5b9e\uff0c\u7279\u610frun\u4e86\u4e0b\u7ed9\u5927\u5bb6\u770b\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202012\/2020-12-25_000917.png\" width=\"408\" height=\"182\" alt=\"\u5143\u7d20\u83b7\u53d6\u9009\u62e9\u5668\u51fa\u9519\u63d0\u793a\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0c\u5728\u4f7f\u7528<code>querySelector()<\/code>\u65b9\u6cd5\u7684\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u91cc\u9762\u7684\u9009\u62e9\u5668\u8fdb\u884c\u5408\u6cd5\u6027\u6821\u9a8c\uff0c\u6216\u8005try&#8230;catch\u5904\u7406\uff0c\u5426\u5219\u5c31\u4f1a\u5f71\u54cd\u6574\u4e2aJavaScript\u4ee3\u7801\u7684\u8fd0\u884c\u3002<\/p>\n<p>\u9ebb\u70e6\uff01<\/p>\n<p>\u56e0\u6b64\uff0c\u5982\u679c\u6761\u4ef6\u53ef\u4ee5\uff0c\u4f18\u5148\u4f7f\u7528<code>getElementById()<\/code>\u65b9\u6cd5\u53bb\u83b7\u53d6DOM\u5143\u7d20\u3002<\/p>\n<p><span class=\"hidden\">\/\/zxx: \u5982\u679c\u4f60\u770b\u5230\u8fd9\u6bb5\u6587\u5b57\uff0c\u8bf4\u660e\u4f60\u73b0\u5728\u8bbf\u95ee\u662f\u4f53\u9a8c\u7cdf\u7cd5\u7684\u5783\u573e\u76d7\u7248\u7f51\u7ad9\uff0c\u4f60\u53ef\u4ee5\u8bbf\u95ee\u539f\u6587\u83b7\u5f97\u5f88\u597d\u7684\u4f53\u9a8c\uff1ahttps:\/\/www.zhangxinxu.com\/wordpress\/?p=9747\uff08\u4f5c\u8005\u5f20\u946b\u65ed\uff09<\/span><\/p>\n<h3>\u56db\u3001append\u5bf9\u6bd4appendChild<\/h3>\n<p><code>append()<\/code> API\u65b9\u6cd5<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=6443\">\u4ee5\u524d\u5176\u5b9e\u4e5f\u4ecb\u7ecd\u8fc7<\/a>\uff0c\u548c\u5f88\u591aAPI\u5728\u4e00\u8d77\u4ecb\u7ecd\u7684\uff0c\u5927\u5bb6\u53ef\u80fd\u6ca1\u6ce8\u610f\uff0c\u8fd9\u91cc\u518d\u8bb2\u4e0b\u3002<\/p>\n<p>\u5bf9\u4e8e\u8282\u70b9\uff0c<code>append<\/code>\u548c<code>appendChild<\/code>\u529f\u80fd\u57fa\u672c\u662f\u4e00\u81f4\u7684\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>let div = document.createElement('div');\r\ndiv.content = '\u6b22\u8fce\u5206\u4eab\u5230\u4f60\u7684\u670b\u53cb\u5708';\r\n<span style=\"color:green;\">\/\/ \u4e0b\u9762\u4e24\u884c\u4f5c\u7528\u4e00\u6837\u7684<\/span>\r\ndocument.body.append(div);\r\n<span style=\"color:green;\">\/\/ \u7b49\u540c\u4e8e<\/span>\r\ndocument.body.appendChild(div);<\/pre>\n<p>\u90fd\u80fd\u5728\u5143\u7d20\u7684\u540e\u9762\u6dfb\u52a0DOM\u8282\u70b9\u5143\u7d20\uff0c\u5305\u62ec\u6587\u672c\u8282\u70b9\uff0c\u6ce8\u91ca\u8282\u70b9\uff0c\u5143\u7d20\u7b49\u90fd\u53ef\u4ee5\u3002<\/p>\n<p>\u533a\u522b\u5728\u4e8e\u4e0b\u9762\uff1a<\/p>\n<ol>\n<li><code>append()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u4e00\u6b21append\u591a\u4e2a\u5143\u7d20\uff0c\u4f8b\u5982\uff1a\n<pre>dom.append(node1, node2, node3, ...)<\/pre>\n<p><code>appendChild<\/code>\u65b9\u6cd5\u53ea\u80fd\u4e00\u6b21append\u4e00\u4e2a\u5143\u7d20\u3002<\/li>\n<li><code>append()<\/code>\u65b9\u6cd5\u8fd8\u53ef\u4ee5<code>append<\/code>\u5b57\u7b26\u4e32\uff08\u4f1a\u81ea\u52a8HTML\u8f6c\u4e49\uff09\u3002\u4f8b\u5982\uff1a\n<pre>document.body.append('<img decoding=\"async\" src=\"1.jpg\">', '<img decoding=\"async\" src=\"2.jpg\">');<\/pre>\n<p>\u6700\u540e\u9875\u9762\u4e0a\u51fa\u73b0\u7684\u4e0d\u662f\u56fe\u7247\uff0c\u800c\u662f\u76f8\u5173\u7684\u8f6c\u4e49\u540e\u7684HTML\u5b57\u7b26\u4e32\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202012\/2020-12-25_002551.png\" width=\"294\" height=\"93\" alt=\"append HTML\u5b57\u7b26\u4e32\u7ed3\u679c\u793a\u610f\" class=\"alignnone size-medium\" \/>\n<\/li>\n<\/ol>\n<h3>\u4e94\u3001scrollIntoView\u5bf9\u6bd4scrollIntoViewIfNeeded<\/h3>\n<p><code>scrollIntoView<\/code>\u548c<code>scrollIntoViewIfNeeded<\/code>\u65b9\u6cd5\u7684\u533a\u522b\u4e3b\u89812\u70b9\uff1a<\/p>\n<ol>\n<li><strong>\u884c\u4e3a\u4e0a\u7684\u533a\u522b<\/strong><br \/>\n\u5982\u679c\u5143\u7d20\u5df2\u7ecf\u5728\u89c6\u533a\u4e86\uff0c\u5219<code>scrollIntoViewIfNeeded()<\/code>\u65b9\u6cd5\u6267\u884c\u7684\u65f6\u5019\uff0c\u9875\u9762\u662f\u4e0d\u4f1a\u6eda\u52a8\u5b9a\u4f4d\u7684\u3002\n<\/li>\n<li><strong>\u8bed\u6cd5\u4e0a\u7684\u533a\u522b<\/strong><br \/>\n<code>scrollIntoView()<\/code>\u652f\u6301\u8bbe\u7f6e\u6eda\u52a8\u5b9a\u4f4d\u7684\u65f6\u5019\u662f\u5426\u662f\u5e73\u6ed1\u6eda\u52a8\uff0c\u53c2\u6570\u662fsmooth\uff0c\u8be6\u89c1\u6211\u7684\u8fd9\u7bc7\u6587\u7ae0\u201c<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=8073\">CSS scroll-behavior\u548cJS scrollIntoView\u8ba9\u9875\u9762\u6eda\u52a8\u5e73\u6ed1<\/a>\u201d\u3002<\/p>\n<p><code>scrollIntoViewIfNeeded()<\/code>\u7684\u6eda\u52a8\u5b9a\u4f4d\u53ea\u80fd\u662f\u786c\u90a6\u90a6\u7684\u6548\u679c\u3002<\/p>\n<p>\u4ee5\u53ca<code>scrollIntoView()<\/code>\u652f\u6301\u7cbe\u51c6\u8bbe\u7f6e\u5b9a\u4f4d\u7684\u5143\u7d20\u662f\u5b9a\u4f4d\u5230\u89c6\u533a\u7684\u4e0a\u65b9\u3001\u4e0b\u65b9\u8fd8\u662f\u4e2d\u95f4\uff0c\u8bed\u6cd5\u53c2\u6570\u4f7f\u7528\u793a\u610f\u5982\u4e0b\uff1a<\/p>\n<pre>element.scrollIntoView({\r\n    <span style=\"color:green;\">\/\/ \u8fd8\u652f\u6301start\u548cend\u503c<\/span>\r\n    block: 'center',\r\n    <span style=\"color:green;\">\/\/ \u5e73\u6ed1\u6eda\u52a8<\/span>\r\n    behavior: 'smooth'\r\n});<\/pre>\n<p>\u800c<code>scrollIntoViewIfNeeded()<\/code>\u7684\u5b9a\u4f4d\u4f4d\u7f6e\u5c31\u6bd4\u8f83\u7c97\u7cd9\uff0c\u65e0\u6cd5\u7cbe\u786e\uff0c\u53ea\u652f\u6301\u4e00\u4e2aBoolean\u53c2\u6570\u503c\uff0ctrue\u8868\u793a\u5c45\u4e2d\uff0cfalse\u8868\u793a\u6216\u4e0a\u8fb9\u7f18\u6216\u4e0b\u8fb9\u7f18\u3002<\/p>\n<pre><span style=\"color:green;\">\/\/ \u89c6\u533a\u5c45\u4e2d\u5b9a\u4f4d<\/span>\r\nelement.scrollIntoViewIfNeeded(true);\r\n<span style=\"color:green;\">\/\/ \u89c6\u533a\u4e0a\u8fb9\u7f18\u6216\u4e0b\u8fb9\u7f18\u6eda\u52a8\u5b9a\u4f4d<\/span>\r\nelement.scrollIntoViewIfNeeded(false);<\/pre>\n<\/li>\n<\/ol>\n<p>\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e24\u4e2a\u65b9\u6cd5\u662f\u53ef\u4ee5\u4e92\u76f8\u66ff\u6362\u4f7f\u7528\u7684\u3002<\/p>\n<h3>\u516d\u3001\u7ed3\u8bed<\/h3>\n<p>\u5f53\u7136\uff0c\u8fd8\u6709\u5f88\u591a\u5176\u4ed6\u529f\u80fd\u53ef\u4ee5\u4e92\u76f8\u66ff\u4ee3\uff0c\u4f46\u662f\u5b9e\u9645\u4e0a\u6709\u7ec6\u8282\u5dee\u5f02\u7684DOM API\uff0c\u6b22\u8fce\u8865\u5145\uff0c\u6211\u4f1a\u53ca\u65f6\u66f4\u65b0\u3002<\/p>\n<p>\u611f\u8c22\u60a8\u7684\u9605\u8bfb\uff0c\u5982\u679c\u60a8\u89c9\u5f97\u672c\u6587\u5185\u5bb9\u8fd8\u4e0d\u9519\uff0c\u6b22\u8fce\u5206\u4eab\uff0c\u8ba9\u66f4\u591a\u7684\u5c0f\u4f19\u4f34\u77e5\u9053\u3002<\/p>\n<p>\u6700\u540e\u795d\u5927\u5bb6\u5723\u8bde\u8282\u5feb\u4e50\uff0c\u9a6c\u745e\u4e8f\u745e\u7f8e\u601d\uff0c\u7b11\u53e3\u5e38\u5f00\uff0c^_^<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/1f601.svg\" width=\"20\" height=\"20\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u6b22\u8fce\u5206\u4eab\uff0c\u52ff\u5168\u6587\u8f6c\u8f7d\uff0c\u5982\u679c\u5b9e\u5728\u559c\u6b22\uff0c\u53ef\u6536\u85cf\uff0c\u6c38\u4e0d\u8fc7\u671f\uff0c\u4e14\u4f1a\u53ca\u65f6\u66f4\u65b0\u77e5\u8bc6\u70b9\u53ca\u4fee\u6b63\u9519\u8bef\uff0c\u9605\u8bfb\u4f53\u9a8c\u4e5f\u66f4\u597d\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9747\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=9747<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202012\/dom-api-diff-cover.png\" width=\"160\" height=\"103\" alt=\"\u5723\u8bde\u8282\u5feb\u4e50\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>\u4ecb\u7ecd5\u7ec4\u90e8\u5206\u529f\u80fd\u91cd\u53e0\u7684DOM API\uff0c\u5e26\u5927\u5bb6\u770b\u770b\u4f60\u53ef\u80fd\u4e0d\u77e5\u9053\u7684\u4e00\u4e9b\u7ec6\u8282\u5dee\u5f02\uff0c\u5e0c\u671b\u8fd9\u4e9b\u5bf9\u6bd4\u53ef\u4ee5\u5bf9\u60a8\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1284],"tags":[77,604,182,716,1695,1483,1023,624,1696,1484],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/9747"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=9747"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/9747\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=9747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=9747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=9747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}