{"id":883,"date":"2025-12-22T10:31:36","date_gmt":"2025-12-22T02:31:36","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=883"},"modified":"2025-12-22T10:31:36","modified_gmt":"2025-12-22T02:31:36","slug":"html-tablecss%e5%ae%9e%e7%8e%b0%e5%8f%af%e7%bc%96%e8%be%91%e8%a1%a8%e6%a0%bc%e7%9a%84%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a0%81-2","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/22\/html-tablecss%e5%ae%9e%e7%8e%b0%e5%8f%af%e7%bc%96%e8%be%91%e8%a1%a8%e6%a0%bc%e7%9a%84%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a0%81-2\/","title":{"rendered":"html table+css\u5b9e\u73b0\u53ef\u7f16\u8f91\u8868\u683c\u7684\u793a\u4f8b\u4ee3\u7801\u00a0"},"content":{"rendered":"\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 \u7eaf HTML + CSS + \u5c11\u91cf JavaScript \u5b9e\u73b0\u7684\u53ef\u7f16\u8f91\u8868\u683c\u793a\u4f8b\uff0c\u652f\u6301\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u70b9\u51fb\u5355\u5143\u683c\u76f4\u63a5\u7f16\u8f91\uff08input \u8f93\u5165\u6846\uff09<\/li>\n\n\n\n<li>\u6309 Enter \u4fdd\u5b58<\/li>\n\n\n\n<li>\u6309 Esc \u53d6\u6d88<\/li>\n\n\n\n<li>\u652f\u6301\u52a8\u6001\u6dfb\u52a0\/\u5220\u9664\u884c\uff08\u53ef\u9009\u6269\u5c55\uff09<\/li>\n<\/ul>\n\n\n\n<p>html<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;!DOCTYPE html&gt;\n&amp;lt;html lang=&quot;zh-CN&quot;&gt;\n&amp;lt;head&gt;\n  &amp;lt;meta charset=&quot;UTF-8&quot; \/&gt;\n  &amp;lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;\/&gt;\n  &amp;lt;title&gt;\u53ef\u7f16\u8f91 HTML \u8868\u683c&amp;lt;\/title&gt;\n  &amp;lt;style&gt;\n    body {\n      font-family: Arial, Helvetica, sans-serif;\n      margin: 40px;\n      background: #f5f5f5;\n    }\n\n    .container {\n      max-width: 900px;\n      margin: 0 auto;\n    }\n\n    table {\n      width: 100%;\n      border-collapse: collapse;\n      background: white;\n      box-shadow: 0 2px 10px rgba(0,0,0,0.1);\n      border-radius: 8px;\n      overflow: hidden;\n    }\n\n    th, td {\n      padding: 12px 15px;\n      text-align: left;\n      border-bottom: 1px solid #ddd;\n    }\n\n    th {\n      background-color: #4a90e2;\n      color: white;\n      font-weight: bold;\n    }\n\n    tr:hover {\n      background-color: #f8f9fa;\n    }\n\n    td.editable {\n      cursor: pointer;\n      position: relative;\n    }\n\n    td.editable:hover {\n      background-color: #e3f2fd;\n    }\n\n    \/* \u7f16\u8f91\u72b6\u6001\u4e0b\u7684\u8f93\u5165\u6846 *\/\n    td.editing input {\n      width: 100%;\n      padding: 6px 8px;\n      border: 2px solid #4a90e2;\n      border-radius: 4px;\n      outline: none;\n      font-size: 1em;\n    }\n\n    \/* \u64cd\u4f5c\u6309\u94ae *\/\n    .actions {\n      text-align: center;\n    }\n\n    button {\n      padding: 6px 12px;\n      margin: 0 4px;\n      border: none;\n      border-radius: 4px;\n      cursor: pointer;\n      font-size: 0.9em;\n    }\n\n    .btn-add {\n      background: #28a745;\n      color: white;\n    }\n\n    .btn-delete {\n      background: #dc3545;\n      color: white;\n    }\n\n    .btn-save {\n      background: #17a2b8;\n      color: white;\n    }\n  &amp;lt;\/style&gt;\n&amp;lt;\/head&gt;\n&amp;lt;body&gt;\n  &amp;lt;div class=&quot;container&quot;&gt;\n    &amp;lt;h2&gt;\u53ef\u7f16\u8f91\u8868\u683c\u793a\u4f8b&amp;lt;\/h2&gt;\n\n    &amp;lt;button class=&quot;btn-add&quot; onclick=&quot;addRow()&quot;&gt;+ \u6dfb\u52a0\u4e00\u884c&amp;lt;\/button&gt;\n\n    &amp;lt;table id=&quot;editableTable&quot;&gt;\n      &amp;lt;thead&gt;\n        &amp;lt;tr&gt;\n          &amp;lt;th&gt;\u59d3\u540d&amp;lt;\/th&gt;\n          &amp;lt;th&gt;\u5e74\u9f84&amp;lt;\/th&gt;\n          &amp;lt;th&gt;\u57ce\u5e02&amp;lt;\/th&gt;\n          &amp;lt;th&gt;\u64cd\u4f5c&amp;lt;\/th&gt;\n        &amp;lt;\/tr&gt;\n      &amp;lt;\/thead&gt;\n      &amp;lt;tbody&gt;\n        &amp;lt;tr&gt;\n          &amp;lt;td class=&quot;editable&quot; data-field=&quot;name&quot;&gt;\u5f20\u4e09&amp;lt;\/td&gt;\n          &amp;lt;td class=&quot;editable&quot; data-field=&quot;age&quot;&gt;28&amp;lt;\/td&gt;\n          &amp;lt;td class=&quot;editable&quot; data-field=&quot;city&quot;&gt;\u5317\u4eac&amp;lt;\/td&gt;\n          &amp;lt;td class=&quot;actions&quot;&gt;\n            &amp;lt;button class=&quot;btn-delete&quot; onclick=&quot;deleteRow(this)&quot;&gt;\u5220\u9664&amp;lt;\/button&gt;\n          &amp;lt;\/td&gt;\n        &amp;lt;\/tr&gt;\n        &amp;lt;tr&gt;\n          &amp;lt;td class=&quot;editable&quot; data-field=&quot;name&quot;&gt;\u674e\u56db&amp;lt;\/td&gt;\n          &amp;lt;td class=&quot;editable&quot; data-field=&quot;age&quot;&gt;34&amp;lt;\/td&gt;\n          &amp;lt;td class=&quot;editable&quot; data-field=&quot;city&quot;&gt;\u4e0a\u6d77&amp;lt;\/td&gt;\n          &amp;lt;td class=&quot;actions&quot;&gt;\n            &amp;lt;button class=&quot;btn-delete&quot; onclick=&quot;deleteRow(this)&quot;&gt;\u5220\u9664&amp;lt;\/button&gt;\n          &amp;lt;\/td&gt;\n        &amp;lt;\/tr&gt;\n      &amp;lt;\/tbody&gt;\n    &amp;lt;\/table&gt;\n  &amp;lt;\/div&gt;\n\n  &amp;lt;script&gt;\n    \/\/ \u70b9\u51fb\u5355\u5143\u683c\u8fdb\u5165\u7f16\u8f91\u6a21\u5f0f\n    document.querySelectorAll(&#039;.editable&#039;).forEach(cell =&gt; {\n      cell.addEventListener(&#039;click&#039;, function() {\n        if (this.classList.contains(&#039;editing&#039;)) return;\n\n        const originalValue = this.textContent.trim();\n        const input = document.createElement(&#039;input&#039;);\n        input.type = &#039;text&#039;;\n        input.value = originalValue;\n\n        \/\/ \u6e05\u7a7a\u5e76\u653e\u5165 input\n        this.textContent = &#039;&#039;;\n        this.appendChild(input);\n        this.classList.add(&#039;editing&#039;);\n\n        \/\/ \u81ea\u52a8\u805a\u7126\n        input.focus();\n\n        \/\/ Enter \u4fdd\u5b58\uff0cEsc \u53d6\u6d88\n        input.addEventListener(&#039;keydown&#039;, function(e) {\n          if (e.key === &#039;Enter&#039;) {\n            saveEdit(cell, input.value);\n          } else if (e.key === &#039;Escape&#039;) {\n            cancelEdit(cell, originalValue);\n          }\n        });\n\n        \/\/ \u5931\u53bb\u7126\u70b9\u4e5f\u4fdd\u5b58\n        input.addEventListener(&#039;blur&#039;, () =&gt; {\n          saveEdit(cell, input.value);\n        });\n      });\n    });\n\n    \/\/ \u4fdd\u5b58\u7f16\u8f91\n    function saveEdit(cell, newValue) {\n      cell.textContent = newValue.trim() || &#039;\u2014&#039;;\n      cell.classList.remove(&#039;editing&#039;);\n    }\n\n    \/\/ \u53d6\u6d88\u7f16\u8f91\n    function cancelEdit(cell, originalValue) {\n      cell.textContent = originalValue;\n      cell.classList.remove(&#039;editing&#039;);\n    }\n\n    \/\/ \u6dfb\u52a0\u65b0\u884c\n    function addRow() {\n      const table = document.getElementById(&#039;editableTable&#039;).getElementsByTagName(&#039;tbody&#039;)&#x5B;0];\n      const newRow = table.insertRow();\n\n      \/\/ \u521b\u5efa\u53ef\u7f16\u8f91\u5355\u5143\u683c\n      &#x5B;&#039;name&#039;, &#039;age&#039;, &#039;city&#039;].forEach(field =&gt; {\n        const cell = newRow.insertCell();\n        cell.className = &#039;editable&#039;;\n        cell.dataset.field = field;\n        cell.textContent = &#039;\u70b9\u51fb\u7f16\u8f91&#039;;\n        \/\/ \u91cd\u65b0\u7ed1\u5b9a\u70b9\u51fb\u4e8b\u4ef6\n        cell.addEventListener(&#039;click&#039;, function() {\n          \/\/ \u590d\u7528\u4e0a\u9762\u7684\u70b9\u51fb\u903b\u8f91\uff08\u53ef\u63d0\u53d6\u4e3a\u51fd\u6570\u66f4\u4f18\u96c5\uff09\n          if (this.classList.contains(&#039;editing&#039;)) return;\n          const originalValue = this.textContent.trim();\n          const input = document.createElement(&#039;input&#039;);\n          input.value = originalValue;\n          this.textContent = &#039;&#039;;\n          this.appendChild(input);\n          this.classList.add(&#039;editing&#039;);\n          input.focus();\n\n          input.addEventListener(&#039;keydown&#039;, e =&gt; {\n            if (e.key === &#039;Enter&#039;) saveEdit(this, input.value);\n            if (e.key === &#039;Escape&#039;) cancelEdit(this, originalValue);\n          });\n          input.addEventListener(&#039;blur&#039;, () =&gt; saveEdit(this, input.value));\n        });\n      });\n\n      \/\/ \u64cd\u4f5c\u5217\n      const actionCell = newRow.insertCell();\n      actionCell.className = &#039;actions&#039;;\n      actionCell.innerHTML = `&amp;lt;button class=&quot;btn-delete&quot; onclick=&quot;deleteRow(this)&quot;&gt;\u5220\u9664&amp;lt;\/button&gt;`;\n    }\n\n    \/\/ \u5220\u9664\u884c\n    function deleteRow(btn) {\n      if (confirm(&#039;\u786e\u5b9a\u5220\u9664\u6b64\u884c\uff1f&#039;)) {\n        const row = btn.closest(&#039;tr&#039;);\n        row.remove();\n      }\n    }\n  &amp;lt;\/script&gt;\n&amp;lt;\/body&gt;\n&amp;lt;\/html&gt;\n<\/pre><\/div>\n\n\n<p>\u4e3b\u8981\u7279\u70b9\u8bf4\u660e\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u70b9\u51fb\u5373\u7f16\u8f91\uff1a\u5355\u5143\u683c\u70b9\u51fb\u540e\u53d8\u6210\u8f93\u5165\u6846<\/li>\n\n\n\n<li>Enter \u4fdd\u5b58 \/ Esc \u53d6\u6d88 \/ \u5931\u7126\u4fdd\u5b58<\/li>\n\n\n\n<li>\u52a8\u6001\u6dfb\u52a0\u884c\uff1a\u70b9\u51fb\u201c+ \u6dfb\u52a0\u4e00\u884c\u201d\u81ea\u52a8\u65b0\u589e\u53ef\u7f16\u8f91\u884c<\/li>\n\n\n\n<li>\u5220\u9664\u529f\u80fd\uff1a\u6bcf\u884c\u6709\u5220\u9664\u6309\u94ae<\/li>\n\n\n\n<li>\u7eaf\u524d\u7aef\uff1a\u65e0\u9700\u540e\u7aef\u3001\u65e0\u6846\u67b6\uff0c\u6613\u4e8e\u7406\u89e3\u548c\u4fee\u6539<\/li>\n<\/ul>\n\n\n\n<p>\u8fdb\u9636\u5efa\u8bae\uff08\u6839\u636e\u9700\u6c42\u53ef\u6269\u5c55\uff09\uff1a<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>\u6570\u636e\u6301\u4e45\u5316 \u2192 \u7ed3\u5408 localStorage \u4fdd\u5b58<\/li>\n\n\n\n<li>\u5b57\u6bb5\u6821\u9a8c \u2192 \u5728\u4fdd\u5b58\u65f6\u7528\u6b63\u5219\u6821\u9a8c\u5e74\u9f84\u662f\u5426\u4e3a\u6570\u5b57<\/li>\n\n\n\n<li>\u6279\u91cf\u64cd\u4f5c \u2192 \u6dfb\u52a0\u591a\u9009\u5220\u9664\u3001\u5168\u9009\u529f\u80fd<\/li>\n\n\n\n<li>\u6837\u5f0f\u7f8e\u5316 \u2192 \u5f15\u5165 Tailwind CSS \u6216 Element Plus \u98ce\u683c<\/li>\n\n\n\n<li>\u771f\u5b9e\u6570\u636e \u2192 \u901a\u8fc7 fetch \u4ece\u540e\u7aef\u52a0\u8f7d JSON \u6570\u636e<\/li>\n<\/ol>\n\n\n\n<p>\u9700\u8981\u66f4\u590d\u6742\u7684\u529f\u80fd\uff08\u5982\u6392\u5e8f\u3001\u8fc7\u6ee4\u3001\u5206\u9875\u3001\u5bfc\u51fa Excel \u7b49\uff09\u4e5f\u53ef\u4ee5\u544a\u8bc9\u6211\uff0c\u6211\u518d\u5e2e\u4f60\u6269\u5c55\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 \u7eaf HTML + CSS + \u5c11\u91cf JavaScript \u5b9e\u73b0\u7684&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/22\/html-tablecss%e5%ae%9e%e7%8e%b0%e5%8f%af%e7%bc%96%e8%be%91%e8%a1%a8%e6%a0%bc%e7%9a%84%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a0%81-2\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-883","post","type-post","status-publish","format-standard","hentry","category-html-xhtml"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/883","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=883"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/883\/revisions"}],"predecessor-version":[{"id":886,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/883\/revisions\/886"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}