{"id":12,"date":"2025-11-20T16:30:19","date_gmt":"2025-11-20T08:30:19","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=12"},"modified":"2025-11-20T16:30:19","modified_gmt":"2025-11-20T08:30:19","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","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/11\/20\/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\/","title":{"rendered":"html table+css\u5b9e\u73b0\u53ef\u7f16\u8f91\u8868\u683c\u7684\u793a\u4f8b\u4ee3\u7801"},"content":{"rendered":"\n<p>\u8981\u5b9e\u73b0\u4e00\u4e2a\u53ef\u7f16\u8f91\u7684\u8868\u683c\uff0c\u53ef\u4ee5\u4f7f\u7528 HTML \u8868\u683c (<code>&lt;table&gt;<\/code>) \u548c CSS \u6837\u5f0f\uff0c\u518d\u7ed3\u5408 JavaScript \u6765\u4f7f\u8868\u683c\u4e2d\u7684\u5355\u5143\u683c\u53ef\u7f16\u8f91\u3002\u4f60\u53ef\u4ee5\u5229\u7528 HTML \u7684&nbsp;<code>contenteditable<\/code>&nbsp;\u5c5e\u6027\u6765\u5b9e\u73b0\u6bcf\u4e2a\u5355\u5143\u683c\u7684\u7f16\u8f91\u529f\u80fd\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u53ef\u7f16\u8f91\u8868\u683c\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u5305\u542b\u4e86 HTML\u3001CSS \u548c JavaScript\uff0c\u5141\u8bb8\u7528\u6237\u70b9\u51fb\u8868\u683c\u4e2d\u7684\u5355\u5143\u683c\u8fdb\u884c\u7f16\u8f91\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b\u4ee3\u7801\uff1a<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">HTML:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html lang=\"en\"&gt;\n&lt;head&gt;\n    &lt;meta charset=\"UTF-8\"&gt;\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n    &lt;title&gt;\u53ef\u7f16\u8f91\u8868\u683c&lt;\/title&gt;\n    &lt;link rel=\"stylesheet\" href=\"styles.css\"&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n\n    &lt;h2&gt;\u53ef\u7f16\u8f91\u8868\u683c\u793a\u4f8b&lt;\/h2&gt;\n\n    &lt;table class=\"editable-table\"&gt;\n        &lt;thead&gt;\n            &lt;tr&gt;\n                &lt;th&gt;\u59d3\u540d&lt;\/th&gt;\n                &lt;th&gt;\u5e74\u9f84&lt;\/th&gt;\n                &lt;th&gt;\u804c\u4e1a&lt;\/th&gt;\n                &lt;th&gt;\u90ae\u7bb1&lt;\/th&gt;\n            &lt;\/tr&gt;\n        &lt;\/thead&gt;\n        &lt;tbody&gt;\n            &lt;tr&gt;\n                &lt;td contenteditable=\"true\"&gt;\u5f20\u4e09&lt;\/td&gt;\n                &lt;td contenteditable=\"true\"&gt;28&lt;\/td&gt;\n                &lt;td contenteditable=\"true\"&gt;\u5de5\u7a0b\u5e08&lt;\/td&gt;\n                &lt;td contenteditable=\"true\"&gt;zhangsan@example.com&lt;\/td&gt;\n            &lt;\/tr&gt;\n            &lt;tr&gt;\n                &lt;td contenteditable=\"true\"&gt;\u674e\u56db&lt;\/td&gt;\n                &lt;td contenteditable=\"true\"&gt;35&lt;\/td&gt;\n                &lt;td contenteditable=\"true\"&gt;\u8bbe\u8ba1\u5e08&lt;\/td&gt;\n                &lt;td contenteditable=\"true\"&gt;lisi@example.com&lt;\/td&gt;\n            &lt;\/tr&gt;\n            &lt;tr&gt;\n                &lt;td contenteditable=\"true\"&gt;\u738b\u4e94&lt;\/td&gt;\n                &lt;td contenteditable=\"true\"&gt;42&lt;\/td&gt;\n                &lt;td contenteditable=\"true\"&gt;\u4ea7\u54c1\u7ecf\u7406&lt;\/td&gt;\n                &lt;td contenteditable=\"true\"&gt;wangwu@example.com&lt;\/td&gt;\n            &lt;\/tr&gt;\n        &lt;\/tbody&gt;\n    &lt;\/table&gt;\n\n    &lt;script src=\"scripts.js\"&gt;&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">CSS (styles.css):<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>body {\n    font-family: Arial, sans-serif;\n    margin: 0;\n    padding: 20px;\n    background-color: #f4f4f4;\n}\n\nh2 {\n    text-align: center;\n}\n\ntable {\n    width: 100%;\n    border-collapse: collapse;\n    margin: 20px 0;\n    background-color: white;\n    border-radius: 8px;\n    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);\n}\n\nth, td {\n    padding: 10px 15px;\n    border: 1px solid #ddd;\n    text-align: center;\n}\n\nth {\n    background-color: #f7f7f7;\n}\n\ntd&#91;contenteditable=\"true\"]:empty:before {\n    content: \"\u70b9\u51fb\u7f16\u8f91...\";\n    color: #999;\n}\n\ntd&#91;contenteditable=\"true\"]:empty {\n    background-color: #fafafa;\n}\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">JavaScript (scripts.js):<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u5982\u679c\u9700\u8981\u4fdd\u5b58\u7f16\u8f91\u540e\u7684\u5185\u5bb9\u5230\u672c\u5730\u5b58\u50a8\u6216\u53d1\u9001\u5230\u670d\u52a1\u5668\uff0c\u53ef\u4ee5\u5728\u8fd9\u91cc\u6dfb\u52a0\u4ee3\u7801\ndocument.querySelectorAll('td&#91;contenteditable=\"true\"]').forEach(cell =&gt; {\n    cell.addEventListener('input', (e) =&gt; {\n        \/\/ \u53ef\u4ee5\u6839\u636e\u9700\u6c42\u5c06\u7f16\u8f91\u5185\u5bb9\u4fdd\u5b58\u6216\u5904\u7406\n        console.log(`\u5185\u5bb9\u5df2\u66f4\u6539: ${e.target.innerText}`);\n    });\n});\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u89e3\u91ca\uff1a<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>HTML<\/strong>:\n<ul class=\"wp-block-list\">\n<li>\u8868\u683c\u4f7f\u7528\u00a0<code>&lt;table><\/code>\u00a0\u6807\u7b7e\u5b9a\u4e49\uff0c\u8868\u5934\u00a0<code>&lt;thead><\/code>\u00a0\u90e8\u5206\u5b9a\u4e49\u4e86\u5217\u7684\u540d\u79f0\uff0c\u8868\u4f53\u00a0<code>&lt;tbody><\/code>\u00a0\u5305\u542b\u4e86\u53ef\u7f16\u8f91\u7684\u5355\u5143\u683c (<code>&lt;td><\/code>)\uff0c\u8fd9\u4e9b\u5355\u5143\u683c\u4f7f\u7528\u00a0<code>contenteditable=\"true\"<\/code>\u00a0\u5c5e\u6027\uff0c\u4f7f\u5176\u6210\u4e3a\u53ef\u7f16\u8f91\u533a\u57df\u3002<\/li>\n\n\n\n<li>\u7528\u6237\u70b9\u51fb\u5e76\u7f16\u8f91\u5355\u5143\u683c\u65f6\uff0c\u5185\u5bb9\u4f1a\u5373\u65f6\u66f4\u65b0\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>CSS<\/strong>:\n<ul class=\"wp-block-list\">\n<li>\u8868\u683c\u6837\u5f0f\u5305\u62ec\u8bbe\u7f6e\u00a0<code>border-collapse<\/code>\u00a0\u6765\u5408\u5e76\u8fb9\u6846\uff0c<code>padding<\/code>\u00a0\u7528\u4e8e\u6dfb\u52a0\u5185\u8fb9\u8ddd\uff0c\u4f7f\u8868\u683c\u770b\u8d77\u6765\u66f4\u52a0\u7f8e\u89c2\u3002<\/li>\n\n\n\n<li><code>td[contenteditable=\"true\"]:empty:before<\/code>\u00a0\u8fd9\u884c\u4ee3\u7801\u4e3a\u672a\u8f93\u5165\u5185\u5bb9\u7684\u5355\u5143\u683c\u63d0\u4f9b\u4e00\u4e2a\u63d0\u793a\uff0c\u6307\u793a\u7528\u6237\u70b9\u51fb\u7f16\u8f91\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>JavaScript<\/strong>:\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528\u00a0<code>input<\/code>\u00a0\u4e8b\u4ef6\u76d1\u542c\u7528\u6237\u7f16\u8f91\u5355\u5143\u683c\u5185\u5bb9\u7684\u8fc7\u7a0b\u3002\u5f53\u7528\u6237\u8f93\u5165\u6216\u4fee\u6539\u5185\u5bb9\u65f6\uff0c\u53ef\u4ee5\u5c06\u65b0\u5185\u5bb9\u4fdd\u5b58\u5230\u53d8\u91cf\u3001\u670d\u52a1\u5668\u6216\u672c\u5730\u5b58\u50a8\u3002<\/li>\n\n\n\n<li>\u8fd9\u91cc\u53ea\u662f\u7b80\u5355\u5730\u901a\u8fc7\u00a0<code>console.log()<\/code>\u00a0\u8f93\u51fa\u4fee\u6539\u540e\u7684\u5185\u5bb9\uff0c\u5b9e\u9645\u5e94\u7528\u4e2d\u53ef\u4ee5\u901a\u8fc7 AJAX \u6216\u5176\u4ed6\u65b9\u6cd5\u5c06\u6570\u636e\u53d1\u9001\u5230\u540e\u53f0\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u53ef\u6269\u5c55\u6027\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u9a8c\u8bc1<\/strong>: \u4f60\u53ef\u4ee5\u5728\u00a0<code>input<\/code>\u00a0\u4e8b\u4ef6\u4e2d\u6dfb\u52a0\u8f93\u5165\u9a8c\u8bc1\uff0c\u6bd4\u5982\u786e\u4fdd\u90ae\u7bb1\u683c\u5f0f\u6b63\u786e\u3001\u5e74\u9f84\u4e3a\u6570\u5b57\u7b49\u3002<\/li>\n\n\n\n<li><strong>\u6570\u636e\u6301\u4e45\u5316<\/strong>: \u5982\u679c\u4f60\u60f3\u8ba9\u8868\u683c\u7684\u7f16\u8f91\u5185\u5bb9\u6301\u4e45\u4fdd\u5b58\uff0c\u53ef\u4ee5\u4f7f\u7528\u00a0<code>localStorage<\/code>\u00a0\u6216\u901a\u8fc7\u8868\u5355\u63d0\u4ea4\u6570\u636e\u5230\u670d\u52a1\u5668\u3002<\/li>\n\n\n\n<li><strong>\u6837\u5f0f\u6539\u8fdb<\/strong>: \u53ef\u4ee5\u8fdb\u4e00\u6b65\u4f18\u5316\u7f16\u8f91\u6846\u7684\u6837\u5f0f\uff0c\u6bd4\u5982\u6dfb\u52a0\u7126\u70b9\u65f6\u7684\u9ad8\u4eae\u6548\u679c\u6216\u7981\u7528\u67d0\u4e9b\u5355\u5143\u683c\u7684\u7f16\u8f91\u529f\u80fd\u7b49\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u8fd9\u6837\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728\u9875\u9762\u4e0a\u521b\u5efa\u4e00\u4e2a\u53ef\u7f16\u8f91\u7684\u8868\u683c\uff0c\u5141\u8bb8\u7528\u6237\u76f4\u63a5\u4fee\u6539\u8868\u683c\u4e2d\u7684\u5185\u5bb9\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8981\u5b9e\u73b0\u4e00\u4e2a\u53ef\u7f16\u8f91\u7684\u8868\u683c\uff0c\u53ef\u4ee5\u4f7f\u7528 HTML \u8868\u683c (&lt;table&gt;)&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/11\/20\/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\/\">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-12","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\/12","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=12"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"predecessor-version":[{"id":13,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/12\/revisions\/13"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}