{"id":85094,"date":"2023-12-15T14:12:54","date_gmt":"2023-12-15T14:12:54","guid":{"rendered":"https:\/\/abbyhsia.com\/?p=85094"},"modified":"2025-04-15T11:14:46","modified_gmt":"2025-04-15T11:14:46","slug":"noteinnerhtml-and-createelement-methods-for-dom-element-manipulation","status":"publish","type":"post","link":"https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/","title":{"rendered":"[Note]&#8217;innerHTML&#8217; and &#8216;createElement&#8217; Methods for DOM Element Manipulation.-JavaScript"},"content":{"rendered":"\n<p>Cover Credits to <a href=\"https:\/\/dribbble.com\/Volorf\">Oleg Frolov<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is DOM in JavaScript?<\/h2>\n\n\n\n<p>Document Object Model(DOM)\u6587\u6a94\u6a21\u578b\uff0c \u7c21\u55ae\u4f86\u8aaa\u5c31\u662fHTML\u7bc0\u9ede\uff0c\u5305\u542b\u4e86\u7236\u5b50\u53ca\u5144\u5f1f\u4e4b\u9593\u5c64\u7d1a\u5143\u7d20\u95dc\u4fc2\uff0c\u53ef\u4ee5\u900f\u904e\u9644\u52a0\u7a0b\u5f0f\u78bc\u53bb\u5275\u5efa\u3001\u4fee\u6539\u3001\u522a\u9664\u7bc0\u9ede\u6216\u9032\u884c\u4e8b\u4ef6\u8655\u7406\u3002<\/p>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a0e5380959a7&quot;}\" data-wp-interactive=\"core\/image\" class=\"wp-block-image size-full is-style-default wp-lightbox-container\"><img decoding=\"async\" width=\"1484\" height=\"764\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/abbyhsia.com\/wp-content\/uploads\/2023\/12\/DOM.jpg\" alt=\"\" class=\"wp-image-85096\" srcset=\"https:\/\/abbyhsia.com\/wp-content\/uploads\/2023\/12\/DOM.jpg 1484w, https:\/\/abbyhsia.com\/wp-content\/uploads\/2023\/12\/DOM-300x154.jpg 300w, https:\/\/abbyhsia.com\/wp-content\/uploads\/2023\/12\/DOM-1024x527.jpg 1024w, https:\/\/abbyhsia.com\/wp-content\/uploads\/2023\/12\/DOM-768x395.jpg 768w, https:\/\/abbyhsia.com\/wp-content\/uploads\/2023\/12\/DOM-350x180.jpg 350w\" sizes=\"(max-width: 1484px) 100vw, 1484px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"\u653e\u5927\u5716\u7247\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on-async--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">DOM\u80fd\u505a\u5230\u4ec0\u9ebc\uff1f<\/h2>\n\n\n\n<p>\u5982\u4e0a\u6bb5\u5716\u793a\u6240\u898bDOM\u7522\u751f\u6a39\u72c0\u7d50\u69cb\uff0cJS\u53ef\u4ee5\u900f\u904eDOM\u53bb\u64cd\u63a7\u7bc0\u9ede\uff0c\u63a7\u5236CSS\uff0c\u589e\u52a0\u4e92\u52d5\u6548\u679c\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u5148\u4ee5\u76ee\u524d\u5b78\u7fd2\u5230\u300c\u7372\u53d6\u3001\u589e\u52a0\u7bc0\u9ede\u300dJS\u8a9e\u6cd5\u7b46\u8a18\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-Fira-Code\" style=\"font-size:.875rem;font-family:Code-Pro-Fira-Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#0f111a\"><span style=\"background:#aaafcf;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#0f111a\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/get elements form dom\ndocument.getElmentbyId();\/\/\u552f\u4e00\u5143\u4ef6\ndocument.querySelector();\/\/\u55ae\u500b\u5143\u4ef6\ndocument.querySelectorAll();\/\/\u904d\u6b77\u8907\u6578\u540c\u5c64\u5143\u7d20\n\n\/\/add elements\ndocument.createElment('');\/\/\u5275\u5efa\u5143\u7d20\nel.textcontext=''\/\/\u589e\u52a0\u6587\u5b57\nel.appendChild('');\/\/\u5c07\u5efa\u7acb\u7684\u5143\u7d20\u653e\u5728\u5c0d\u61c9\u7bc0\u9ede\u4e4b\u4e0b\n\nel.innerHTML='&lt;p&gt;'+'HI'+'&lt;\/p&gt;';\/\/\u5c07\u5143\u7d20\u653e\u5230DOM\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-ocean\" style=\"background-color: #0F111A\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/get elements form dom<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">getElmentbyId<\/span><span style=\"color: #BABED8\">()<\/span><span style=\"color: #89DDFF\">;<\/span><span style=\"color: #464B5D; font-style: italic\">\/\/\u552f\u4e00\u5143\u4ef6<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">querySelector<\/span><span style=\"color: #BABED8\">()<\/span><span style=\"color: #89DDFF\">;<\/span><span style=\"color: #464B5D; font-style: italic\">\/\/\u55ae\u500b\u5143\u4ef6<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">querySelectorAll<\/span><span style=\"color: #BABED8\">()<\/span><span style=\"color: #89DDFF\">;<\/span><span style=\"color: #464B5D; font-style: italic\">\/\/\u904d\u6b77\u8907\u6578\u540c\u5c64\u5143\u7d20<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/add elements<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">createElment<\/span><span style=\"color: #BABED8\">(<\/span><span style=\"color: #89DDFF\">&#39;&#39;<\/span><span style=\"color: #BABED8\">)<\/span><span style=\"color: #89DDFF\">;<\/span><span style=\"color: #464B5D; font-style: italic\">\/\/\u5275\u5efa\u5143\u7d20<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">el<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">textcontext<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #89DDFF\">&#39;&#39;<\/span><span style=\"color: #464B5D; font-style: italic\">\/\/\u589e\u52a0\u6587\u5b57<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">el<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">appendChild<\/span><span style=\"color: #BABED8\">(<\/span><span style=\"color: #89DDFF\">&#39;&#39;<\/span><span style=\"color: #BABED8\">)<\/span><span style=\"color: #89DDFF\">;<\/span><span style=\"color: #464B5D; font-style: italic\">\/\/\u5c07\u5efa\u7acb\u7684\u5143\u7d20\u653e\u5728\u5c0d\u61c9\u7bc0\u9ede\u4e4b\u4e0b<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">el<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">innerHTML<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">&lt;p&gt;<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">+<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">HI<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">+<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">&lt;\/p&gt;<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">;<\/span><span style=\"color: #464B5D; font-style: italic\">\/\/\u5c07\u5143\u7d20\u653e\u5230DOM<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u5982\u4f55\u53d6\u5f97\u7bc0\u9ede(Node)<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>document.getElmentbyID<\/strong><\/h3>\n\n\n\n<p>Html\u4f7f\u7528\u5177\u6709\u552f\u4e00\u6027\u8cea\u6a19\u7c64\u201did\u201d\u547d\u540d\u5143\u7d20\uff0c\u5728JS\u8fd4\u56de\u4e00\u500b\u5143\u7d20\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-Fira-Code\" style=\"font-size:.875rem;font-family:Code-Pro-Fira-Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#22272e\"><span style=\"background:#9eadbd;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#22272e\">HTML<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;h1 id=&quot;title&quot;&gt;&lt;\/h1&gt;\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ADBAC7\">&lt;<\/span><span style=\"color: #8DDB8C\">h1<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">id<\/span><span style=\"color: #ADBAC7\">=<\/span><span style=\"color: #96D0FF\">&quot;title&quot;<\/span><span style=\"color: #ADBAC7\">&gt;&lt;\/<\/span><span style=\"color: #8DDB8C\">h1<\/span><span style=\"color: #ADBAC7\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-Fira-Code\" style=\"font-size:.875rem;font-family:Code-Pro-Fira-Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#0f111a\"><span style=\"background:#aaafcf;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#0f111a\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"const el =document.getElementById('title');\nconsole.log(el);\n\/\/Output\uff1a&lt;h1 id=&quot;title&quot;&gt;&lt;\/h1&gt;\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-ocean\" style=\"background-color: #0F111A\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C792EA\">const<\/span><span style=\"color: #BABED8\"> el <\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\">document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">getElementById<\/span><span style=\"color: #BABED8\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">title<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #BABED8\">)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">console<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">log<\/span><span style=\"color: #BABED8\">(el)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/Output\uff1a&lt;h1 id=&quot;title&quot;&gt;&lt;\/h1&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>document.getElementsByClassName<\/strong><\/h3>\n\n\n\n<p>\u53ef\u53d6\u5f97\u55ae\u6216\u8907\u6578\u540c\u985e\u540d\u5143\u7d20\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-Fira-Code\" style=\"font-size:.875rem;font-family:Code-Pro-Fira-Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#22272e\"><span style=\"background:#9eadbd;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#22272e\">HTML<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;div class=&quot;block&quot;&gt;&lt;\/div&gt;\n&lt;div class=&quot;block&quot;&gt;&lt;\/div&gt;\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ADBAC7\">&lt;<\/span><span style=\"color: #8DDB8C\">div<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">class<\/span><span style=\"color: #ADBAC7\">=<\/span><span style=\"color: #96D0FF\">&quot;block&quot;<\/span><span style=\"color: #ADBAC7\">&gt;&lt;\/<\/span><span style=\"color: #8DDB8C\">div<\/span><span style=\"color: #ADBAC7\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">&lt;<\/span><span style=\"color: #8DDB8C\">div<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">class<\/span><span style=\"color: #ADBAC7\">=<\/span><span style=\"color: #96D0FF\">&quot;block&quot;<\/span><span style=\"color: #ADBAC7\">&gt;&lt;\/<\/span><span style=\"color: #8DDB8C\">div<\/span><span style=\"color: #ADBAC7\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-Fira-Code\" style=\"font-size:.875rem;font-family:Code-Pro-Fira-Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#0f111a\"><span style=\"background:#aaafcf;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#0f111a\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"let el=document.getElementsByClassName('block');\nel.length(el)\n\/\/Output:2\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-ocean\" style=\"background-color: #0F111A\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C792EA\">let<\/span><span style=\"color: #BABED8\"> el<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\">document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">getElementsByClassName<\/span><span style=\"color: #BABED8\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">block<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #BABED8\">)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">el<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">length<\/span><span style=\"color: #BABED8\">(el)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/Output:2<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>document.querySelector<\/strong><\/h4>\n\n\n\n<p>\u53d6\u55ae\u500b\u5143\u7d20\uff0c\u82e5\u6709\u8907\u6578\u540c\u547d\u540d\u53ea\u6703\u53d6\u7b2c\u4e00\u500b\u503c\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-Fira-Code\" style=\"font-size:.875rem;font-family:Code-Pro-Fira-Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#22272e\"><span style=\"background:#9eadbd;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#22272e\">HTML<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;ul&gt;\n&lt;li class=&quot;name&quot;&gt;Dorami&lt;\/li&gt;\n&lt;li class=&quot;name&quot;&gt;Doraemon&lt;\/li&gt;\n&lt;\/ul&gt;\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ADBAC7\">&lt;<\/span><span style=\"color: #8DDB8C\">ul<\/span><span style=\"color: #ADBAC7\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">&lt;<\/span><span style=\"color: #8DDB8C\">li<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">class<\/span><span style=\"color: #ADBAC7\">=<\/span><span style=\"color: #96D0FF\">&quot;name&quot;<\/span><span style=\"color: #ADBAC7\">&gt;Dorami&lt;\/<\/span><span style=\"color: #8DDB8C\">li<\/span><span style=\"color: #ADBAC7\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">&lt;<\/span><span style=\"color: #8DDB8C\">li<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">class<\/span><span style=\"color: #ADBAC7\">=<\/span><span style=\"color: #96D0FF\">&quot;name&quot;<\/span><span style=\"color: #ADBAC7\">&gt;Doraemon&lt;\/<\/span><span style=\"color: #8DDB8C\">li<\/span><span style=\"color: #ADBAC7\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">&lt;\/<\/span><span style=\"color: #8DDB8C\">ul<\/span><span style=\"color: #ADBAC7\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-Fira-Code\" style=\"font-size:.875rem;font-family:Code-Pro-Fira-Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#0f111a\"><span style=\"background:#aaafcf;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#0f111a\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"const list=document.querySelector('.name')\nconsole.log(list);\n\/\/Output:Dorami\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-ocean\" style=\"background-color: #0F111A\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C792EA\">const<\/span><span style=\"color: #BABED8\"> list<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\">document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">querySelector<\/span><span style=\"color: #BABED8\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">.name<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #BABED8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">console<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">log<\/span><span style=\"color: #BABED8\">(list)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/Output:Dorami<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>document.querySelectorAll<\/strong><\/h3>\n\n\n\n<p>\u53ef\u9078\u53d6\u91cd\u8907\u985e\u540d\u76f8\u540c\u5143\u7d20\uff0c\u89e3\u6790\u7db2\u9801\u6642\u6703\u7531\u4e0a\u81f3\u4e0b\u904d\u6b77DOM\u53d6\u51fa\u300c\u5168\u90e8\u76f8\u540c\u300d\u7bc0\u9ede\u4ee5\u985e\u9663\u5217\u65b9\u5f0f\u56de\u50b3\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-Fira-Code\" style=\"font-size:.875rem;font-family:Code-Pro-Fira-Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#22272e\"><span style=\"background:#9eadbd;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#22272e\">HTML<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;ul&gt;\n&lt;li class=&quot;name&quot;&gt;&lt;\/li&gt;\n&lt;li class=&quot;name&quot;&gt;&lt;\/li&gt;\n&lt;\/ul&gt;\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ADBAC7\">&lt;<\/span><span style=\"color: #8DDB8C\">ul<\/span><span style=\"color: #ADBAC7\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">&lt;<\/span><span style=\"color: #8DDB8C\">li<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">class<\/span><span style=\"color: #ADBAC7\">=<\/span><span style=\"color: #96D0FF\">&quot;name&quot;<\/span><span style=\"color: #ADBAC7\">&gt;&lt;\/<\/span><span style=\"color: #8DDB8C\">li<\/span><span style=\"color: #ADBAC7\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">&lt;<\/span><span style=\"color: #8DDB8C\">li<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">class<\/span><span style=\"color: #ADBAC7\">=<\/span><span style=\"color: #96D0FF\">&quot;name&quot;<\/span><span style=\"color: #ADBAC7\">&gt;&lt;\/<\/span><span style=\"color: #8DDB8C\">li<\/span><span style=\"color: #ADBAC7\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #ADBAC7\">&lt;\/<\/span><span style=\"color: #8DDB8C\">ul<\/span><span style=\"color: #ADBAC7\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-Fira-Code\" style=\"font-size:.875rem;font-family:Code-Pro-Fira-Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#0f111a\"><span style=\"background:#aaafcf;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#0f111a\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"const list=document.querySelectorAll('.name');\nconsole.log(list.length);\n\/\/Output: 2\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-ocean\" style=\"background-color: #0F111A\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C792EA\">const<\/span><span style=\"color: #BABED8\"> list<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\">document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">querySelectorAll<\/span><span style=\"color: #BABED8\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">.name<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #BABED8\">)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">console<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">log<\/span><span style=\"color: #BABED8\">(list<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">length)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/Output: 2<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<p><\/p>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u7528JS\u6539\u8b8a\u7d50\u69cb<\/h2>\n\n\n\n<p>\u53ef\u4ee5\u900f\u904eJS\u5169\u7a2e\u65b9\u5f0f\u52d5\u614b\u65b0\u589e\u7bc0\u9ede\uff0c\u5206\u5225\u662fcreateElement, innerHTML\uff0c\u4e0d\u904e\u524d\u8005\u6703\u5beb\u6bd4\u8f03\u591a\u884c\u7a0b\u5f0f\u78bc\uff0c\u5f8c\u8005\u5c07\u5b57\u4e32\u7d44\u5408\u5f8c\u4e00\u6b21\u5e36\u5165\u5373\u53ef\uff0c\u6211\u5011\u8acb\u5927\u96c4\u8ddf\u5bb6\u4eba\u505a\u793a\u7bc4\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>CreateElement<\/strong><\/h3>\n\n\n\n<p>JS\u4e2d\u4f7f\u7528CreateElement\u589e\u52a0\u7bc0\u9ede\uff0c\u5c07\u8a72\u5143\u7d20\u7bc0\u9ede\u900f\u904eappendChild\u52a0\u5165DOM\u6307\u5b9a\u7bc0\u9ede\u4e4b\u4e0b\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-Fira-Code\" style=\"font-size:.875rem;font-family:Code-Pro-Fira-Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#22272e\"><span style=\"background:#9eadbd;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#22272e\">HTML<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;ul class=&quot;family&quot;&gt;&lt;\/ul&gt;\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ADBAC7\">&lt;<\/span><span style=\"color: #8DDB8C\">ul<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">class<\/span><span style=\"color: #ADBAC7\">=<\/span><span style=\"color: #96D0FF\">&quot;family&quot;<\/span><span style=\"color: #ADBAC7\">&gt;&lt;\/<\/span><span style=\"color: #8DDB8C\">ul<\/span><span style=\"color: #ADBAC7\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-Fira-Code\" style=\"font-size:.875rem;font-family:Code-Pro-Fira-Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#0f111a\"><span style=\"background:#aaafcf;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#0f111a\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/createElement\n\nlet getel=document.querySelector('.family')\nconst family=[\n{ name:'NOBITA',\n  food:'pancake',\nimg:'https:\/\/chinesedora.com\/character\/nobita_mes.gif'\n},\n{ name:'DoRAEMON',\n  food:'Dorayaki',\nimg:'https:\/\/chinesedora.com\/character\/doraemon12.png'\n},\n{ name:&quot;NOBITA's Dad&quot;,\n\tfood:'Dorayaki',\n  img:'https:\/\/chinesedora.com\/images\/nobifa.jpg'\n},\n{ name:&quot;NOBITA's Mom&quot;,\n\tfood:'Dorayaki',\nimg:'https:\/\/chinesedora.com\/images\/nobima.jpg'\n}\n]\n\nfunction addEl(){\n for (let i=0;i&lt;family.length;i++){\n\/\/name\nlet addName=document.createElement('li');\naddName.textContent=family[i].name;\ngetel.appendChild(addName);\n   \n\/\/food\nlet addFood=document.createElement('p');\naddFood.textContent='\u6211\u559c\u6b61\u5403'+family[i].food;\naddName.appendChild(addFood);\n   \n\/\/img\nlet addImg=document.createElement('img')\naddImg.src=family[i].img;\naddName.appendChild(addImg);\n}\n}\n  \naddEl();\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-ocean\" style=\"background-color: #0F111A\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/createElement<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">let<\/span><span style=\"color: #BABED8\"> getel<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\">document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">querySelector<\/span><span style=\"color: #BABED8\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">.family<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #BABED8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">const<\/span><span style=\"color: #BABED8\"> family<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #F07178\">name<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">NOBITA<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">  <\/span><span style=\"color: #F07178\">food<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">pancake<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F07178\">img<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">https:\/\/chinesedora.com\/character\/nobita_mes.gif<\/span><span style=\"color: #89DDFF\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">},<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #F07178\">name<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">DoRAEMON<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">  <\/span><span style=\"color: #F07178\">food<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">Dorayaki<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F07178\">img<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">https:\/\/chinesedora.com\/character\/doraemon12.png<\/span><span style=\"color: #89DDFF\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">},<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #F07178\">name<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">NOBITA&#39;s Dad<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\t<\/span><span style=\"color: #F07178\">food<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">Dorayaki<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">  <\/span><span style=\"color: #F07178\">img<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">https:\/\/chinesedora.com\/images\/nobifa.jpg<\/span><span style=\"color: #89DDFF\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">},<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #F07178\">name<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">NOBITA&#39;s Mom<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\t<\/span><span style=\"color: #F07178\">food<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">Dorayaki<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F07178\">img<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">https:\/\/chinesedora.com\/images\/nobima.jpg<\/span><span style=\"color: #89DDFF\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">]<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">function<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #82AAFF\">addEl<\/span><span style=\"color: #89DDFF\">(){<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F07178\"> <\/span><span style=\"color: #89DDFF; font-style: italic\">for<\/span><span style=\"color: #F07178\"> (<\/span><span style=\"color: #C792EA\">let<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #BABED8\">i<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #F78C6C\">0<\/span><span style=\"color: #89DDFF\">;<\/span><span style=\"color: #BABED8\">i<\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #BABED8\">family<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">length<\/span><span style=\"color: #89DDFF\">;<\/span><span style=\"color: #BABED8\">i<\/span><span style=\"color: #89DDFF\">++<\/span><span style=\"color: #F07178\">)<\/span><span style=\"color: #89DDFF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/name<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">let<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #BABED8\">addName<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\">document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">createElement<\/span><span style=\"color: #F07178\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">li<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #F07178\">)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">addName<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">textContent<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\">family<\/span><span style=\"color: #F07178\">[<\/span><span style=\"color: #BABED8\">i<\/span><span style=\"color: #F07178\">]<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">name<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">getel<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">appendChild<\/span><span style=\"color: #F07178\">(<\/span><span style=\"color: #BABED8\">addName<\/span><span style=\"color: #F07178\">)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F07178\">   <\/span><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/food<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">let<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #BABED8\">addFood<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\">document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">createElement<\/span><span style=\"color: #F07178\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">p<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #F07178\">)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">addFood<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">textContent<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">\u6211\u559c\u6b61\u5403<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">+<\/span><span style=\"color: #BABED8\">family<\/span><span style=\"color: #F07178\">[<\/span><span style=\"color: #BABED8\">i<\/span><span style=\"color: #F07178\">]<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">food<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">addName<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">appendChild<\/span><span style=\"color: #F07178\">(<\/span><span style=\"color: #BABED8\">addFood<\/span><span style=\"color: #F07178\">)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F07178\">   <\/span><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/img<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">let<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #BABED8\">addImg<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\">document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">createElement<\/span><span style=\"color: #F07178\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">img<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #F07178\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">addImg<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">src<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\">family<\/span><span style=\"color: #F07178\">[<\/span><span style=\"color: #BABED8\">i<\/span><span style=\"color: #F07178\">]<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">img<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">addName<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">appendChild<\/span><span style=\"color: #F07178\">(<\/span><span style=\"color: #BABED8\">addImg<\/span><span style=\"color: #F07178\">)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #82AAFF\">addEl<\/span><span style=\"color: #BABED8\">()<\/span><span style=\"color: #89DDFF\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>innerHTML<\/strong><\/h3>\n\n\n\n<p>\u53ef\u4ee5\u900f\u904eDOM\u5c6c\u6027\u8655\u7406\u5df2\u5b58\u5728HTML\u7bc0\u9ede\uff0c\u82e5\u500b\u5225\u5e36\u5165\u8cc7\u6599\uff0c\u5f97\u5728\u8ff4\u5708\u4e4b\u5916\u653e\u7a7a\u5b57\u4e32\uff0c\u5c07\u6bcf\u7b46\u8cc7\u6599\u653e\u5165\u5ba3\u544a\u7a7a\u5b57\u4e32\u986f\u793a\u7d50\u679c\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-Fira-Code\" style=\"font-size:.875rem;font-family:Code-Pro-Fira-Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#22272e\"><span style=\"background:#9eadbd;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#22272e\">HTML<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;ul class=&quot;family&quot;&gt;&lt;\/ul&gt;\" style=\"color:#adbac7;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-dark-dimmed\" style=\"background-color: #22272e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #ADBAC7\">&lt;<\/span><span style=\"color: #8DDB8C\">ul<\/span><span style=\"color: #ADBAC7\"> <\/span><span style=\"color: #6CB6FF\">class<\/span><span style=\"color: #ADBAC7\">=<\/span><span style=\"color: #96D0FF\">&quot;family&quot;<\/span><span style=\"color: #ADBAC7\">&gt;&lt;\/<\/span><span style=\"color: #8DDB8C\">ul<\/span><span style=\"color: #ADBAC7\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-Fira-Code\" style=\"font-size:.875rem;font-family:Code-Pro-Fira-Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#0f111a\"><span style=\"background:#aaafcf;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#0f111a\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/\/InnerHTML\n\nlet getel=document.querySelector('.family')\nconst family=[\n{ name:'NOBITA',\n  food:'pancake',\nimg:'https:\/\/chinesedora.com\/character\/nobita_mes.gif'\n},\n{ name:'DoRAEMON',\n  food:'Dorayaki',\nimg:'https:\/\/chinesedora.com\/character\/doraemon12.png'\n},\n{ name:&quot;NOBITA's Dad&quot;,\n\tfood:'Dorayaki',\n  img:'https:\/\/chinesedora.com\/images\/nobifa.jpg'\n},\n{ name:&quot;NOBITA's Mom&quot;,\n\tfood:'Dorayaki',\nimg:'https:\/\/chinesedora.com\/images\/nobima.jpg'\n}\n]\n\nfunction addEl(){\nlet str=''\n for (let i=0;i&lt;family.length;i++){\nlet addInfo=` \n    &lt;li&gt;\n        &lt;p&gt;${family[i].name}&lt;\/p&gt;\n        &lt;p&gt;\u6211\u559c\u6b61\u5403${family[i].food}&lt;\/p&gt;\n        &lt;img src=&quot;${family[i].img}&quot;&gt;\n      &lt;\/li&gt;\n    `;\nstr+=addInfo;\ngetel.innerHTML=str;\n}\n}\n\n\n\naddEl();\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-ocean\" style=\"background-color: #0F111A\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/InnerHTML<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">let<\/span><span style=\"color: #BABED8\"> getel<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\">document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">querySelector<\/span><span style=\"color: #BABED8\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">.family<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #BABED8\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">const<\/span><span style=\"color: #BABED8\"> family<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\">[<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #F07178\">name<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">NOBITA<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">  <\/span><span style=\"color: #F07178\">food<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">pancake<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F07178\">img<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">https:\/\/chinesedora.com\/character\/nobita_mes.gif<\/span><span style=\"color: #89DDFF\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">},<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #F07178\">name<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">DoRAEMON<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">  <\/span><span style=\"color: #F07178\">food<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">Dorayaki<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F07178\">img<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">https:\/\/chinesedora.com\/character\/doraemon12.png<\/span><span style=\"color: #89DDFF\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">},<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #F07178\">name<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">NOBITA&#39;s Dad<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\t<\/span><span style=\"color: #F07178\">food<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">Dorayaki<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">  <\/span><span style=\"color: #F07178\">img<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">https:\/\/chinesedora.com\/images\/nobifa.jpg<\/span><span style=\"color: #89DDFF\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">},<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">{<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #F07178\">name<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">NOBITA&#39;s Mom<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">\t<\/span><span style=\"color: #F07178\">food<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">Dorayaki<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #89DDFF\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F07178\">img<\/span><span style=\"color: #89DDFF\">:<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">https:\/\/chinesedora.com\/images\/nobima.jpg<\/span><span style=\"color: #89DDFF\">&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">]<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">function<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #82AAFF\">addEl<\/span><span style=\"color: #89DDFF\">(){<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">let<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #BABED8\">str<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #89DDFF\">&#39;&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F07178\"> <\/span><span style=\"color: #89DDFF; font-style: italic\">for<\/span><span style=\"color: #F07178\"> (<\/span><span style=\"color: #C792EA\">let<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #BABED8\">i<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #F78C6C\">0<\/span><span style=\"color: #89DDFF\">;<\/span><span style=\"color: #BABED8\">i<\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #BABED8\">family<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">length<\/span><span style=\"color: #89DDFF\">;<\/span><span style=\"color: #BABED8\">i<\/span><span style=\"color: #89DDFF\">++<\/span><span style=\"color: #F07178\">)<\/span><span style=\"color: #89DDFF\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">let<\/span><span style=\"color: #F07178\"> <\/span><span style=\"color: #BABED8\">addInfo<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #89DDFF\">`<\/span><span style=\"color: #C3E88D\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #C3E88D\">    &lt;li&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C3E88D\">        &lt;p&gt;<\/span><span style=\"color: #89DDFF\">${<\/span><span style=\"color: #BABED8\">family[i]<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">name<\/span><span style=\"color: #89DDFF\">}<\/span><span style=\"color: #C3E88D\">&lt;\/p&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C3E88D\">        &lt;p&gt;\u6211\u559c\u6b61\u5403<\/span><span style=\"color: #89DDFF\">${<\/span><span style=\"color: #BABED8\">family[i]<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">food<\/span><span style=\"color: #89DDFF\">}<\/span><span style=\"color: #C3E88D\">&lt;\/p&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C3E88D\">        &lt;img src=&quot;<\/span><span style=\"color: #89DDFF\">${<\/span><span style=\"color: #BABED8\">family[i]<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">img<\/span><span style=\"color: #89DDFF\">}<\/span><span style=\"color: #C3E88D\">&quot;&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C3E88D\">      &lt;\/li&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C3E88D\">    <\/span><span style=\"color: #89DDFF\">`<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">str<\/span><span style=\"color: #89DDFF\">+=<\/span><span style=\"color: #BABED8\">addInfo<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">getel<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">innerHTML<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\">str<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #89DDFF\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #82AAFF\">addEl<\/span><span style=\"color: #BABED8\">()<\/span><span style=\"color: #89DDFF\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\u51fd\u5f0f\u5167\u4f7f\u7528\u5169\u8005\u8655\u7406\u65b9\u5f0f\u4e0d\u540c\uff0c\u5f8c\u8005\u96d6\u7136\u7a0b\u5f0f\u78bc\u884c\u6578\u8f03\u5c11\uff0c\u4f46innerHTML\u5728\u904b\u7528\u4e0a\u8981\u5c0f\u5fc3XSS\u554f\u984c\uff0c\u4e0b\u65b9\u6dfa\u8ac7\u4f55\u70baXSS\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u9810\u9632\u6f5b\u5728 XSS\uff08Cross-Site Scripting)\u653b\u64ca<\/h2>\n\n\n\n<p>\u8de8\u7ad9\u8173\u672c\u653b\u64ca\uff08Cross-Site Scripting, XSS)\uff0cAttacker\u900f\u904e\u7db2\u7ad9\u6f0f\u6d1e\u7d50\u5408\u7528\u6236\u64cd\u4f5c\u65b9\u5f0f\uff0c\u5982\uff1a\u8f38\u5165\u5b57\u4e32\u6b04\u4f4d\u3001URL\u3001Cookie \u57cb\u5165\u60e1\u610f\u8173\u672c\u81f3\u76ee\u6a19\u7db2\u7ad9\uff0c\u4e4b\u5f8c\u8a2a\u554f\u7684\u7528\u6236\u9032\u884c\u700f\u89bd\u4fbf\u6210\u70ba\u653b\u64ca\u5c0d\u8c61\u3002<\/p>\n\n\n\n<p>XSS\u4e09\u7a2e\u653b\u64ca\u65b9\u5f0f[1] \uff1aReflected, <em>DOM-based XSS, Stored XSS\uff0c\u7a0d\u70ba\u89e3\u91cb\u5728<\/em>\u4e0d\u540c\u5834\u666f\u6703\u767c\u751f\u7684\u653b\u64ca\u60c5\u5883\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u53cd\u5c04\u578b\u653b\u64ca\uff08Reflected\uff09<\/h3>\n\n\n\n<p>Attacker\u900f\u904e\u8f38\u5165\u6b04\u4f4d\u5beb\u5165\u60e1\u610f\u8173\u672c\u3002\u7576\u9001\u51fa\u8acb\u6c42\u5230\u4f3a\u670d\u5668\u5f8c\u6703\u904b\u884c\u7a0b\u5f0f\u78bc\uff0c\u4f3a\u670d\u5668\u8fd4\u56de\u7d66\u7528\u6236\u756b\u9762\u6703\u5305\u542b\u525b\u624d\u8f38\u5165\u8173\u672c\u5f8c\u6240\u986f\u793a\u7684\u7d50\u679c\uff0c\u4e4b\u5f8c\u6709\u5176\u4ed6\u7528\u6236\u8a2a\u554f\u5e36\u6709\u9019\u500b\u653b\u64ca\u8173\u672c\u7684\u7279\u6b8a\u8acb\u6c42\u6642\uff0c\u4f3a\u670d\u5668\u6703\u5c07\u8173\u672c\u53cd\u5c04\u56de\u7528\u6236\u7684\u700f\u89bd\u5668\u57f7\u884c\u6b64\u5e36\u6709\u60e1\u610f\u8173\u672c\u7684\u756b\u9762\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5132\u5b58\u578b\u653b\u64ca(Stored XSS\uff09<\/h3>\n\n\n\n<p>\u7528\u6236\u5728\u8a02\u95b1\u7db2\u7ad9\u670d\u52d9\u586b\u5beb\u500b\u4eba\u8cc7\u6599\uff0c\u5982\u4fe1\u7528\u5361\u865f\u7b49\u2026\uff0cAttacker\u6b32\u63d0\u53d6\u8cc7\u6599\u6216\u653b\u64ca\u7db2\u7ad9\uff0c\u53ef\u4ee5\u5728\u6b04\u4f4d\u4e2d\u57cb\u4e0bJS\u8173\u672c\u5b58\u9032\u7db2\u7ad9\u8cc7\u6599\u5eab\uff0c\u5f80\u5f8c\u7528\u6236\u5728\u9019\u9801\u63d0\u4ea4\u654f\u611f\u8cc7\u6599\uff0c\u4fbf\u53ef\u80fd\u6709\u76dc\u53d6\u8cc7\u6599\u98a8\u96aa\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6587\u6a94\u7269\u4ef6\u6a21\u578b\u653b\u64ca\uff08<em>DOM-based XSS\uff09<\/em><\/h3>\n\n\n\n<p>\u8207\u53cd\u5c04\u578b\u96f7\u540c\uff0c\u4e0d\u540c\u4e4b\u8655\u5728\u65bcDOM-based XSS\u662f\u5728\u7528\u6236\u7aef\u700f\u89bd\u5668\u524d\u7aef\u57f7\u884c\uff0c\u800c\u4e0d\u662f\u5728\u4f3a\u670d\u5668\u3002\u900f\u904eJavascript \u6f0f\u6d1e\u5c07\u60e1\u610f\u8173\u672c\u5d4c\u5165DOM\u7bc0\u9ede\u4e4b\u4e2d\uff0c\u7576\u7528\u6236\u8f38\u5165\u6b04\u4f4d\u64cd\u4f5c\uff0c\u57f7\u884cAttacker\u7684\u8173\u672c\uff0c\u9032\u884c\u7aca\u53d6\u4fe1\u606f\u7b49..\u653b\u64ca\u884c\u70ba\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"> innerHTML\u548ccreateElement \u8ddfXSS\u6709\u4ec0\u9ebc\u95dc\u806f\uff1f<\/h2>\n\n\n\n<p>\u9019\u88e1\u7528\u5132\u5b58\u578b\u653b\u64ca(Stored XSS\uff09\u89e3\u91cb\uff0c\u900f\u904eCreateElement\u5efa\u7acb\u7684input\uff0c\u6211\u5011\u5c07\u7528\u6236\u8f38\u5165\u7684\u53c3\u6578\u8f49\u6210\u6587\u672c\u7bc0\u9ede\uff0c\u6240\u4ee5\u5728\u6b04\u4f4d\u8f38\u5165&lt;script&gt;&lt;\/script&gt;\u63d0\u4ea4\u5167\u5bb9\u9001\u5230\u8cc7\u6599\u5eab\uff0c\u6703\u88ab\u7576\u4f5c\u7d14\u6587\u5b57\uff08plaintext\uff09\u8655\u7406\uff0c\u4e0d\u904e\u8f49\u70baString\uff0c\u4e0d\u4ee3\u8868\u5b89\u5168\uff0cAttacker\u9084\u662f\u53ef\u4ee5\u900f\u904e\u5176\u4ed6\u624b\u6cd5\uff0c\u7e5e\u904e\u4e00\u4e9b\u7c21\u55ae\u7684\u9632\u8b77\u6a5f\u5236\u653b\u64ca\u3002<\/p>\n\n\n\n<p>\u56e0\u6b64\uff0c\u9700\u8981\u984d\u5916\u5b89\u5168\u6a5f\u5236\u50cf\u662f\uff1a\u5167\u5bb9\u5b89\u5168\u653f\u7b56[2]\uff08Content Security Policy, CSP)\uff0c\u5141\u8a31\u7db2\u7ad9\u64c1\u6709\u8005\u5236\u5b9a\u4e00\u7d44\u898f\u5247\uff0c\u6307\u5b9a\u54ea\u4e9b\u4f86\u6e90\u7684\u8cc7\u6e90\u53ef\u4ee5\u88ab\u8f09\u5165\u5230\u7db2\u9801\u4e2d\uff0c\u5728\u7528\u6236\u9001\u51fa\u6642\u8acb\u700f\u89bd\u5668\u5728\u5e6b\u5fd9\u6aa2\u67e5\u4e00\u6b21\uff0c\u82e5\u6709\u4e0d\u7b26\u5141\u8a31\u884c\u70ba\uff0c\u53ef\u4ee5\u963b\u64cb\u9019\u4e9b\u8cc7\u6e90\u7684\u8f09\u5165\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-Fira-Code\" style=\"font-size:.875rem;font-family:Code-Pro-Fira-Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#0f111a\"><span style=\"background:#aaafcf;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#0f111a\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"const getEl = document.querySelector('.form');\nconst addInput = document.createElement('input');\n\n\/\/\u7528\u6236\u5728\u6b04\u4f4d\u8f38\u5165\u5167\u5bb9\nconst userType=&quot;&lt;script&gt;'alert('\u6069\u6211\u5728\u653b\u64ca\u4f60')';&lt;\/script&gt;&quot;;\n\/\/\u8f49\u70ba\u7d14\u6587\u5b57\nconst textNode=document.createTextNode(userType);\n\naddInput.appendChild(textNode);\ngetEl.appendChild(addInput);\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-ocean\" style=\"background-color: #0F111A\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C792EA\">const<\/span><span style=\"color: #BABED8\"> getEl <\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\"> document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">querySelector<\/span><span style=\"color: #BABED8\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">.form<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #BABED8\">)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">const<\/span><span style=\"color: #BABED8\"> addInput <\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\"> document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">createElement<\/span><span style=\"color: #BABED8\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">input<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #BABED8\">)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/\u7528\u6236\u5728\u6b04\u4f4d\u8f38\u5165\u5167\u5bb9<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">const<\/span><span style=\"color: #BABED8\"> userType<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">&lt;script&gt;&#39;alert(&#39;\u6069\u6211\u5728\u653b\u64ca\u4f60&#39;)&#39;;&lt;\/script&gt;<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/\u8f49\u70ba\u7d14\u6587\u5b57<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">const<\/span><span style=\"color: #BABED8\"> textNode<\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\">document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">createTextNode<\/span><span style=\"color: #BABED8\">(userType)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">addInput<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">appendChild<\/span><span style=\"color: #BABED8\">(textNode)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">getEl<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">appendChild<\/span><span style=\"color: #BABED8\">(addInput)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u800c\u76f8\u540c\u60c5\u5883\u4ee5innerHTML\u5beb\u6cd5\uff0c\u6703\u88abhtml\u8996\u70ba\u7a0b\u5f0f\u78bc\u57f7\u884cAttacker\u8173\u672c\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-Fira-Code\" style=\"font-size:.875rem;font-family:Code-Pro-Fira-Code,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.5rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#0f111a\"><span style=\"background:#aaafcf;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#0f111a\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" data-code=\"const getEl = document.querySelector('.form');\nconst addInput = document.createElement('input');\n\n\/\/ \u5047\u8a2d\u7528\u6236\u5728\u6b04\u4f4d\u8f38\u5165\u5167\u5bb9\nconst userType = &quot;&lt;script&gt;alert('\u6069\u6211\u5728\u653b\u64ca\u4f60');&lt;\/script&gt;&quot;;\n\n\/\/ innerHTML \u5c07\u7528\u6236\u8f38\u5165\u7684\u5167\u5bb9\u8a2d\u7f6e\u5230 input \u5143\u7d20\u4e2d\naddInput.innerHTML = userType;\n\ngetEl.appendChild(addInput);\" style=\"color:#babed8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme-ocean\" style=\"background-color: #0F111A\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C792EA\">const<\/span><span style=\"color: #BABED8\"> getEl <\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\"> document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">querySelector<\/span><span style=\"color: #BABED8\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">.form<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #BABED8\">)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">const<\/span><span style=\"color: #BABED8\"> addInput <\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\"> document<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">createElement<\/span><span style=\"color: #BABED8\">(<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #C3E88D\">input<\/span><span style=\"color: #89DDFF\">&#39;<\/span><span style=\"color: #BABED8\">)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/ \u5047\u8a2d\u7528\u6236\u5728\u6b04\u4f4d\u8f38\u5165\u5167\u5bb9<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C792EA\">const<\/span><span style=\"color: #BABED8\"> userType <\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\"> <\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">&lt;script&gt;alert(&#39;\u6069\u6211\u5728\u653b\u64ca\u4f60&#39;);&lt;\/script&gt;<\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #464B5D; font-style: italic\">\/\/ innerHTML \u5c07\u7528\u6236\u8f38\u5165\u7684\u5167\u5bb9\u8a2d\u7f6e\u5230 input \u5143\u7d20\u4e2d<\/span><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">addInput<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #BABED8\">innerHTML <\/span><span style=\"color: #89DDFF\">=<\/span><span style=\"color: #BABED8\"> userType<\/span><span style=\"color: #89DDFF\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #BABED8\">getEl<\/span><span style=\"color: #89DDFF\">.<\/span><span style=\"color: #82AAFF\">appendChild<\/span><span style=\"color: #BABED8\">(addInput)<\/span><span style=\"color: #89DDFF\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u4e0d\u904e\uff0c\u4e0a\u8ff0\u4e26\u975e\u6307createElement vs. innerHTML \u9078\u64c7\u524d\u8005\u5b89\u5168\u6027\u8f03\u9ad8\uff0c\u4ee5\u7b46\u8005\u76ee\u524d\u641c\u96c6\u8cc7\u6599\u4f86\u770b\uff0c\u9084\u662f\u5f97\u53d6\u6c7a\u65bc\u60c5\u5883\u4f7f\u7528\uff0c\u4f8b\u5982\u4f60\u7121\u6cd5\u638c\u63a7\u7528\u6236\u6703\u63d0\u4f9b\u7db2\u7ad9\u4ec0\u9ebc\u8cc7\u6599\uff0c\u50cf\u662f\u8f38\u5165\u6b04\u4f4d\u5efa\u8b70\u7528createElement\uff0c\u964d\u4f4eXSS\u653b\u64ca\u3002<\/p>\n\n\n\n<p>\u800c\u6b64\u6587\u4e2d\u63d0\u53caCreateElement\u589e\u52a0\u7bc0\u9ede\uff0c\u50c5\u662f\u5176\u4e2d\u4e00\u9805\u57fa\u672c\u9810\u9632\u63aa\u65bd\uff0c\u76ee\u524d\u770b\u5230\u6709\u95dcXSS\u6280\u8853\u6587\u7ae0\uff0c\u5927\u591a\u5efa\u8b70\u7db2\u7ad9\u505a\u9a57\u8b49\u6216\u904e\u6ffe\u5b57\u4e32\u7b49\u2026\u589e\u52a0\u5b89\u5168\u6a5f\u5236\u5beb\u6cd5\uff0c\u6e1b\u5c11\u88ab\u653b\u64ca\u7684\u53ef\u80fd\u6027\u3002<\/p>\n\n\n\n<p>\u4e0a\u8ff0\u4ee5\u662f\u521d\u5b78<em>XSS<\/em>\u7406\u89e3\u7bc4\u570d\u505a\u7b46\u8a18\uff0c<em>\u82e5\u5f80\u5f8c\u5c0dXSS\u6709\u66f4\u8fd1\u4e00\u6b65\u5b78\u7fd2\u518d\u505a\u6574\u7406<\/em>\u3002<\/p>\n\n\n\n<p>\u6b64\u70ba\u7d00\u9304\u5b78\u7fd2\u904e\u7a0b\uff0c\u5982\u5167\u5bb9\u6709\u8aa4\uff0c\u6b61\u8fce\u7559\u8a00\u6307\u6559\u3002<br>\u5076\u723e\u6703\u756b\u5716\u4f86\u7406\u89e3\u7a0b\u5f0f\u78bc\uff0c\u82e5\u5167\u6587\u5716\u50cf\u6216\u6d41\u7a0b\u5716\u5c0d\u4f60\u7406\u89e3\u6709\u5e6b\u52a9\uff0c\u6b61\u8fce\u81ea\u884c\u53d6\u7528\u3002<\/p>\n\n\n\n<p>\u53c3\u8003:<\/p>\n\n\n\n<p>[ 1 ]<strong><a href=\"https:\/\/tech-blog.cymetrics.io\/posts\/jo\/zerobased-cross-site-scripting\/\">\u96f6\u57fa\u790e\u8cc7\u5b89\u7cfb\u5217\uff08\u4e8c\uff09-\u8a8d\u8b58 XSS\uff08Cross-Site Scripting\uff09<\/a><\/strong><\/p>\n\n\n\n<p>[ 2 <strong>]CSP:<a href=\"https:\/\/ithelp.ithome.com.tw\/articles\/10307460\">\u4f60\u53ef\u80fd\u4e0d\u77e5\u9053\u7684\u5167\u5bb9\u5b89\u5168\u7b56\u7565(Content-Security-Policy, CSP)<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Cover Credits to Ole [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":85104,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-85094","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[Note]&#039;innerHTML&#039; and &#039;createElement&#039; Methods for DOM Element Manipulation.-JavaScript -<\/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:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/\" \/>\n<meta property=\"og:locale\" content=\"zh_TW\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Note]&#039;innerHTML&#039; and &#039;createElement&#039; Methods for DOM Element Manipulation.-JavaScript -\" \/>\n<meta property=\"og:description\" content=\"Cover Credits to Ole [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-12-15T14:12:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-15T11:14:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/abbyhsia.com\/wp-content\/uploads\/2023\/12\/image_processing20201020-3646-1ff95lv.gif\" \/>\n\t<meta property=\"og:image:width\" content=\"1600\" \/>\n\t<meta property=\"og:image:height\" content=\"1200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/gif\" \/>\n<meta name=\"author\" content=\"Abby\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005:\" \/>\n\t<meta name=\"twitter:data1\" content=\"Abby\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9810\u4f30\u95b1\u8b80\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\u9418\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/abbyhsia.com\\\/index.php\\\/2023\\\/12\\\/15\\\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/abbyhsia.com\\\/index.php\\\/2023\\\/12\\\/15\\\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\\\/\"},\"author\":{\"name\":\"Abby\",\"@id\":\"https:\\\/\\\/abbyhsia.com\\\/#\\\/schema\\\/person\\\/2c40b572cad326aa2312d15fb355afd2\"},\"headline\":\"[Note]&#8217;innerHTML&#8217; and &#8216;createElement&#8217; Methods for DOM Element Manipulation.-JavaScript\",\"datePublished\":\"2023-12-15T14:12:54+00:00\",\"dateModified\":\"2025-04-15T11:14:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/abbyhsia.com\\\/index.php\\\/2023\\\/12\\\/15\\\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\\\/\"},\"wordCount\":141,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/abbyhsia.com\\\/index.php\\\/2023\\\/12\\\/15\\\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/abbyhsia.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/image_processing20201020-3646-1ff95lv.gif\",\"articleSection\":[\"Uncategorized\"],\"inLanguage\":\"zh-TW\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/abbyhsia.com\\\/index.php\\\/2023\\\/12\\\/15\\\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/abbyhsia.com\\\/index.php\\\/2023\\\/12\\\/15\\\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\\\/\",\"url\":\"https:\\\/\\\/abbyhsia.com\\\/index.php\\\/2023\\\/12\\\/15\\\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\\\/\",\"name\":\"[Note]'innerHTML' and 'createElement' Methods for DOM Element Manipulation.-JavaScript -\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/abbyhsia.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/abbyhsia.com\\\/index.php\\\/2023\\\/12\\\/15\\\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/abbyhsia.com\\\/index.php\\\/2023\\\/12\\\/15\\\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/abbyhsia.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/image_processing20201020-3646-1ff95lv.gif\",\"datePublished\":\"2023-12-15T14:12:54+00:00\",\"dateModified\":\"2025-04-15T11:14:46+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/abbyhsia.com\\\/#\\\/schema\\\/person\\\/2c40b572cad326aa2312d15fb355afd2\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/abbyhsia.com\\\/index.php\\\/2023\\\/12\\\/15\\\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\\\/#breadcrumb\"},\"inLanguage\":\"zh-TW\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/abbyhsia.com\\\/index.php\\\/2023\\\/12\\\/15\\\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-TW\",\"@id\":\"https:\\\/\\\/abbyhsia.com\\\/index.php\\\/2023\\\/12\\\/15\\\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\\\/#primaryimage\",\"url\":\"https:\\\/\\\/abbyhsia.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/image_processing20201020-3646-1ff95lv.gif\",\"contentUrl\":\"https:\\\/\\\/abbyhsia.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/image_processing20201020-3646-1ff95lv.gif\",\"width\":1600,\"height\":1200},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/abbyhsia.com\\\/index.php\\\/2023\\\/12\\\/15\\\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/abbyhsia.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Note]&#8217;innerHTML&#8217; and &#8216;createElement&#8217; Methods for DOM Element Manipulation.-JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/abbyhsia.com\\\/#website\",\"url\":\"https:\\\/\\\/abbyhsia.com\\\/\",\"name\":\"\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/abbyhsia.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-TW\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/abbyhsia.com\\\/#\\\/schema\\\/person\\\/2c40b572cad326aa2312d15fb355afd2\",\"name\":\"Abby\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-TW\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cd29a57a8d18bf1bcbba6f673c41bda7?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cd29a57a8d18bf1bcbba6f673c41bda7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cd29a57a8d18bf1bcbba6f673c41bda7?s=96&d=mm&r=g\",\"caption\":\"Abby\"},\"url\":\"https:\\\/\\\/abbyhsia.com\\\/index.php\\\/author\\\/joyce505033gmail-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Note]'innerHTML' and 'createElement' Methods for DOM Element Manipulation.-JavaScript -","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:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/","og_locale":"zh_TW","og_type":"article","og_title":"[Note]'innerHTML' and 'createElement' Methods for DOM Element Manipulation.-JavaScript -","og_description":"Cover Credits to Ole [&hellip;]","og_url":"https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/","article_published_time":"2023-12-15T14:12:54+00:00","article_modified_time":"2025-04-15T11:14:46+00:00","og_image":[{"width":1600,"height":1200,"url":"https:\/\/abbyhsia.com\/wp-content\/uploads\/2023\/12\/image_processing20201020-3646-1ff95lv.gif","type":"image\/gif"}],"author":"Abby","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005:":"Abby","\u9810\u4f30\u95b1\u8b80\u6642\u9593":"2 \u5206\u9418"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/#article","isPartOf":{"@id":"https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/"},"author":{"name":"Abby","@id":"https:\/\/abbyhsia.com\/#\/schema\/person\/2c40b572cad326aa2312d15fb355afd2"},"headline":"[Note]&#8217;innerHTML&#8217; and &#8216;createElement&#8217; Methods for DOM Element Manipulation.-JavaScript","datePublished":"2023-12-15T14:12:54+00:00","dateModified":"2025-04-15T11:14:46+00:00","mainEntityOfPage":{"@id":"https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/"},"wordCount":141,"commentCount":0,"image":{"@id":"https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/#primaryimage"},"thumbnailUrl":"https:\/\/abbyhsia.com\/wp-content\/uploads\/2023\/12\/image_processing20201020-3646-1ff95lv.gif","articleSection":["Uncategorized"],"inLanguage":"zh-TW","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/","url":"https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/","name":"[Note]'innerHTML' and 'createElement' Methods for DOM Element Manipulation.-JavaScript -","isPartOf":{"@id":"https:\/\/abbyhsia.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/#primaryimage"},"image":{"@id":"https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/#primaryimage"},"thumbnailUrl":"https:\/\/abbyhsia.com\/wp-content\/uploads\/2023\/12\/image_processing20201020-3646-1ff95lv.gif","datePublished":"2023-12-15T14:12:54+00:00","dateModified":"2025-04-15T11:14:46+00:00","author":{"@id":"https:\/\/abbyhsia.com\/#\/schema\/person\/2c40b572cad326aa2312d15fb355afd2"},"breadcrumb":{"@id":"https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/#breadcrumb"},"inLanguage":"zh-TW","potentialAction":[{"@type":"ReadAction","target":["https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/"]}]},{"@type":"ImageObject","inLanguage":"zh-TW","@id":"https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/#primaryimage","url":"https:\/\/abbyhsia.com\/wp-content\/uploads\/2023\/12\/image_processing20201020-3646-1ff95lv.gif","contentUrl":"https:\/\/abbyhsia.com\/wp-content\/uploads\/2023\/12\/image_processing20201020-3646-1ff95lv.gif","width":1600,"height":1200},{"@type":"BreadcrumbList","@id":"https:\/\/abbyhsia.com\/index.php\/2023\/12\/15\/noteinnerhtml-and-createelement-methods-for-dom-element-manipulation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/abbyhsia.com\/"},{"@type":"ListItem","position":2,"name":"[Note]&#8217;innerHTML&#8217; and &#8216;createElement&#8217; Methods for DOM Element Manipulation.-JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/abbyhsia.com\/#website","url":"https:\/\/abbyhsia.com\/","name":"","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/abbyhsia.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-TW"},{"@type":"Person","@id":"https:\/\/abbyhsia.com\/#\/schema\/person\/2c40b572cad326aa2312d15fb355afd2","name":"Abby","image":{"@type":"ImageObject","inLanguage":"zh-TW","@id":"https:\/\/secure.gravatar.com\/avatar\/cd29a57a8d18bf1bcbba6f673c41bda7?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cd29a57a8d18bf1bcbba6f673c41bda7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cd29a57a8d18bf1bcbba6f673c41bda7?s=96&d=mm&r=g","caption":"Abby"},"url":"https:\/\/abbyhsia.com\/index.php\/author\/joyce505033gmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/abbyhsia.com\/index.php\/wp-json\/wp\/v2\/posts\/85094","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/abbyhsia.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/abbyhsia.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/abbyhsia.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/abbyhsia.com\/index.php\/wp-json\/wp\/v2\/comments?post=85094"}],"version-history":[{"count":56,"href":"https:\/\/abbyhsia.com\/index.php\/wp-json\/wp\/v2\/posts\/85094\/revisions"}],"predecessor-version":[{"id":86329,"href":"https:\/\/abbyhsia.com\/index.php\/wp-json\/wp\/v2\/posts\/85094\/revisions\/86329"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/abbyhsia.com\/index.php\/wp-json\/wp\/v2\/media\/85104"}],"wp:attachment":[{"href":"https:\/\/abbyhsia.com\/index.php\/wp-json\/wp\/v2\/media?parent=85094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/abbyhsia.com\/index.php\/wp-json\/wp\/v2\/categories?post=85094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/abbyhsia.com\/index.php\/wp-json\/wp\/v2\/tags?post=85094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}