{"id":9906,"date":"2021-03-31T00:34:05","date_gmt":"2021-03-30T16:34:05","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9906"},"modified":"2021-03-31T00:34:05","modified_gmt":"2021-03-30T16:34:05","slug":"input-time","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2021\/03\/input-time\/","title":{"rendered":"\u5206\u4eab\u4e0binput time\u8f93\u5165\u6846\u7684\u7ec6\u8282\u77e5\u8bc6"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9906\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=9906<\/a><br \/>\n\u672c\u6587\u6b22\u8fce\u5206\u4eab\u4e0e\u805a\u5408\uff0c\u5168\u6587\u8f6c\u8f7d\u5c31\u4e0d\u5fc5\u4e86\uff0c\u5c0a\u91cd\u7248\u6743\uff0c\u5708\u5b50\u5c31\u8fd9\u4e48\u5927\uff0c\u82e5\u6025\u7528\u53ef\u4ee5\u8054\u7cfb\u6388\u6743\u3002<\/p>\n<p><script>window.wxShareImgUrl = 'https:\/\/www.zhangxinxu.com\/study\/image\/share\/202103-input-time.png';<\/script><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202103\/input-cloud-cover.jpg\" width=\"480\" height=\"304\" alt=\"\u7a7a\u4e2d\u9493\u9c7c-\u5360\u4f4d\u56fe\" class=\"alignright clip thumb size-medium\" \/><\/p>\n<p>\u6700\u8fd1\u4e0etype=&#8221;time&#8221;\u7c7b\u578b\u7684input\u8f93\u5165\u6846\u6253\u4e86\u4e0d\u5c11\u4ea4\u9053\uff0c\u5b66\u5230\u4e86\u4e0d\u5c11\u77e5\u8bc6\uff0c\u548c\u5927\u5bb6\u5206\u4eab\u4e0b\u3002<\/p>\n<h3>\u4e00\u3001\u5173\u4e8e\u517c\u5bb9\u6027\u548cUI\u8868\u73b0<\/h3>\n<h4>1. Safari\u6d4f\u89c8\u5668<\/h4>\n<p>Safari\u684c\u9762\u7aef\u6d4f\u89c8\u5668\u76ee\u524d\u5e76\u4e0d\u652f\u6301time\u8f93\u5165\u6846\uff0c14\u4e4b\u540e\u7684\u7248\u672c\u8c8c\u4f3c\u4f1a\u652f\u6301\uff0c\u517c\u5bb9\u6027\u56fe\u5982\u4e0b\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202103\/2021-03-29_204708.png\" width=\"707\" height=\"458\" alt=\"input\u7c7b\u578b\u8f93\u5165\u6846\" class=\"alignnone size-medium\" \/><\/p>\n<h4>2. Chrome\u6d4f\u89c8\u5668<\/h4>\n<p>Chrome\u6d4f\u89c8\u5668\u7684\u517c\u5bb9\u6027\u76f8\u5f53\u4e0d\u9519\uff0c\u5404\u4e2a\u64cd\u4f5c\u7cfb\u7edf\uff0c\u4ee5\u53ca\u79fb\u52a8\u7aef\u5747\u652f\u6301\u3002<\/p>\n<p>\u5e76\u4e14Chrome\u6d4f\u89c8\u5668\u70b9\u51fb\u8f93\u5165\u6846\u53f3\u4fa7\u7684\u56fe\u6807\u4f1a\u663e\u793a\u4e0b\u62c9\u9009\u62e9\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202103\/chrome-win.png\" width=\"144\" height=\"309\" alt=\"Chrome win\u4e0b\u7684UI\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4f46\u662f\uff0c\u5f88\u5947\u602a\u7684\u662f\uff0c\u6839\u636e\u6211\u5728\u591a\u4e2a\u8bbe\u5907\u4e0a\u6d4b\u8bd5\u3002<\/p>\n<p>Chrome\u6d4f\u89c8\u5668\u5728windows\u7cfb\u7edf\u4e0b\uff0ctime\u662f\u4f7f\u7528\u768424\u5c0f\u65f6\u8868\u793a\u6cd5\uff0c\u6bd4\u8f83\u7b26\u5408\u4e2d\u56fd\u4eba\u770b\u65f6\u95f4\u7684\u4e60\u60ef\u3002<\/p>\n<p>\u4f46\u662fChrome\u6d4f\u89c8\u5668\u5728OS X\u7cfb\u7edf\u4e0b\uff0ctime\u5c45\u7136\u4f7f\u7528\u7684\u662f12\u5c0f\u65f6\u8868\u793a\u6cd5\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202103\/chrome-mac.png\" width=\"188\" height=\"307\" alt=\"Chrome Mac\u8868\u793a\u6cd5\" class=\"alignnone size-medium\" \/><\/p>\n<h4>3. Firefox\u6d4f\u89c8\u5668<\/h4>\n<p>\u4f46\u662f\u5728Windows\u7cfb\u7edf\u4e0b\u7684Firefox\u6d4f\u89c8\u5668\uff0c\u5c45\u7136\u53c8\u662f12\u5c0f\u65f6\u8868\u793a\u6cd5\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202103\/2021-03-30_233326.png\" width=\"115\" height=\"37\" alt=\"Firefox\u6d4f\u89c8\u5668\u4e0b\u6548\u679c\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5e76\u4e14\u6ca1\u6709\u4e0b\u62c9\u5217\u8868\uff0c\u53ea\u80fd\u901a\u8fc7\u4e0a\u4e0b\u952e\u4fee\u6539\u65f6\u95f4\u6216\u8005\u5206\u949f\u3002<\/p>\n<hr>\n<p>\u4e0a\u9762\u8fd9\u51e0\u4e2a\u6d4f\u89c8\u5668UI\u4e0a\u7684\u5dee\u5f02\u7ed9\u5f00\u53d1\u5e26\u6765\u4e86\u4e0d\u5c0f\u7684\u56f0\u6270\u3002<\/p>\n<p>\u9700\u6c42\u662f\u8fd9\u6837\u7684\uff0c\u6240\u6709\u6d4f\u89c8\u5668\u5747\u652f\u6301\u4e0b\u62c9\u7684\u5c0f\u65f6\u548c\u5206\u949f\u9009\u62e9\uff0c\u540c\u65f6\u4fdd\u6301input\u7684\u8f93\u5165\u6846\u662ftime\u7c7b\u578b\uff0c\u8fd9\u6837\u6709\u6700\u4f73\u7684\u8bed\u4e49\u3002<\/p>\n<p>\u4f46\u662f\u65f6\u95f4\u683c\u5f0f\u7684\u4e0d\u4e00\u81f4\uff0c\u4f7f\u5f97\u5f00\u53d1\u7684\u65f6\u5019\u65e0\u6cd5\u786e\u5b9a\uff0c\u4e0b\u62c9\u5e94\u8be5\u662f12\u5c0f\u65f6\u8868\u793a\u8fd8\u662f\u4f7f\u752824\u5c0f\u65f6\u8868\u793a\u3002<\/p>\n<p>\u8fd9\u4e2a\u95ee\u9898\u7684\u89e3\u51b3\u662f\u672c\u6587\u91cd\u70b9\u4ecb\u7ecd\u7684\u5185\u5bb9\u3002<\/p>\n<h3>\u4e8c\u3001\u65f6\u95f4\u8868\u793a\u6cd5\u662f\u65e0\u6cd5\u7edf\u4e00\u7684<\/h3>\n<p>\u6211\u82b1\u4e86\u5927\u91cf\u7684\u65f6\u95f4\u53bb\u7814\u7a76\u80fd\u591f\u901a\u8fc7\u8bbe\u7f6e\u67d0\u4e9b\u5c5e\u6027\uff0c\u4f8b\u5982<code>lang<\/code>\u5c5e\u6027\uff0c\u6216\u8005<code>datetimeformat<\/code>\u5c5e\u6027\u4fee\u6539\u65e5\u671f\u65f6\u95f4\u7684\u663e\u793a\u683c\u5f0f\u3002<\/p>\n<p>\u7ed3\u8bba\u662ftime\/date\u7b49\u7c7b\u578b\u7b49\u65f6\u95f4\u8f93\u5165\u6846\u7b49\u65f6\u95f4\u683c\u5f0f\u662f\u65e0\u6cd5\u6539\u53d8\u7b49\u3002<\/p>\n<p>\u5982\u679c\u5927\u5bb6\u6709\u529e\u6cd5\u53ef\u4ee5\u8bbe\u7f6e\uff0c\u6211\u8bf7\u5927\u5bb6\u5403\u996d\u3002<\/p>\n<p>\u65e2\u7136\u6ca1\u6cd5\u4fdd\u6301\u4e00\u81f4\uff0c\u90a3\u5c31\u65f6\u95f4\u8f93\u5165\u6846\u662f\u4ec0\u4e48\u65f6\u95f4\u683c\u5f0f\uff0cUI\u7ec4\u4ef6\u5b9e\u73b0\u7684\u65f6\u5019\u5c31\u662f\u4ec0\u4e48\u683c\u5f0f\u3002<\/p>\n<p>\u6240\u4ee5\u4e0b\u9762\u7684\u95ee\u9898\u5c31\u53d8\u6210\u4e86\uff0c\u5982\u4f55\u5224\u65ad\u5f53\u524d\u6d4f\u89c8\u5668\u4e0b\u7684time\u8f93\u5165\u6846\u662f24\u5c0f\u65f6\u8868\u793a\u7684\uff0c\u8fd8\u662f12\u5c0f\u65f6\u8868\u793a\u7684\u5462\uff1f<\/p>\n<h3>\u4e8c\u300124\u5c0f\u65f6\u8868\u793a\u8fd8\u662f12\u5c0f\u65f6\u8868\u793a\u7684\u5224\u65ad<\/h3>\n<p>\u662f\u8fd9\u6837\u7684\uff0c\u867d\u7136\u89c6\u89c9\u4e0a\uff0cMac\u8bbe\u5907\u4e0b\u662f12\u5c0f\u65f6\u5236\u7684\uff0c\u4e5f\u5373\u662f\u201c\u4e0a\u5348 11:23\u201d\uff0c\u4f46\u662f\u4f7f\u7528 input.value \u8fd4\u56de\u7684\u4f9d\u7136\u662f24\u5c0f\u65f6\u8868\u793a\u7684\u3002<\/p>\n<p>\u4e5f\u5c31\u662f\u4e0b\u9762\u7684HTML\u4ee3\u7801\uff1a<\/p>\n<pre>&lt;input type=\"time\" value=\"13:14\"&gt;<\/pre>\n<p>\u5728windows Chrome\u6d4f\u89c8\u5668\u4e0b\u663e\u793a\u7684\u662f 13:14\uff0c\u5728windows Firefox\u6d4f\u89c8\u5668\u548cOS X Chrome\u6d4f\u89c8\u5668\u4e0b\u663e\u793a\u7684\u662f \u4e0b\u5348 01:14 \uff0c\u4f46\u662f\u4f7f\u7528value\u5c5e\u6027\u83b7\u53d6\uff0c\u8fd4\u56de\u7684\u5168\u90e8\u90fd\u662f 13:14\uff0c\u5b8c\u5168\u6ca1\u6709\u529e\u6cd5\u901a\u8fc7\u503c\u6765\u5224\u65ad\u5f53\u524d\u6d4f\u89c8\u5668\u652f\u6301\u7684\u662f24\u5c0f\u65f6\u8868\u793aH:mm\uff0c\u8fd8\u662f12\u5c0f\u65f6\u8868\u793aah:mm\u3002<\/p>\n<p><span class=\"hidden\">\/\/zxx: \u5982\u679c\u4f60\u770b\u5230\u8fd9\u6bb5\u6587\u5b57\uff0c\u8bf4\u660e\u4f60\u73b0\u5728\u8bbf\u95ee\u662f\u4f53\u9a8c\u7cdf\u7cd5\u7684\u5783\u573e\u76d7\u7248\u7f51\u7ad9\uff0c\u4f60\u53ef\u4ee5\u8bbf\u95ee\u539f\u6587\u83b7\u5f97\u5f88\u597d\u7684\u4f53\u9a8c\uff1ahttps:\/\/www.zhangxinxu.com\/wordpress\/?p=9906\uff08\u4f5c\u8005\u5f20\u946b\u65ed\uff09<\/span><\/p>\n<p>\u6211\u6709\u60f3\u8fc7\u57fa\u4e8e\u64cd\u4f5c\u7cfb\u7edf\u548c\u6d4f\u89c8\u5668\u5224\u65ad\uff0c\u4f46\u662f\u8fd9\u6837\u7684\u5224\u65ad\u662f\u4e0d\u5b89\u5168\u7684\uff0c\u5bb9\u6613\u51fa\u9519\u7684\uff0c\u56e0\u4e3a\u82f1\u6587 windows\u8bed\u8a00\u64cd\u4f5c\u7cfb\u7edf\u4e0b\u7684Chrome\u4e0d\u89c1\u5f97\u662f24\u5c0f\u65f6\u8868\u793a\u3002<\/p>\n<p>\u600e\u4e48\u529e\u5462\uff0c\u6709\u6ca1\u6709\u4ec0\u4e48\u6bd4\u8f83\u7cbe\u786e\u7684\uff0c\u4e0e\u64cd\u4f5c\u7cfb\u7edf\u65e0\u5173\u7684\u5224\u65ad\u65b9\u6cd5\u5462\uff1f\u540e\u6765\u4f7f\u7528\u4e86\u81ea\u5df1\u8fd8\u89c9\u5f97\u4e0d\u9519\u7684\u4e00\u62db\u3002<\/p>\n<h4>\u5b57\u7b26\u4e2a\u6570\u5bfc\u81f4\u5c3a\u5bf8\u53d8\u5316\u5dee\u5f02\u4e0d\u540c<\/h4>\n<p>\u6d4f\u89c8\u5668\u5982\u679c\u652f\u6301time\u7c7b\u578b\u8f93\u5165\u6846\uff0c\u5219\u8f93\u5165\u6846\u7684\u5c3a\u5bf8\u662f\u8ddf\u7740\u91cc\u9762\u7684\u5b57\u7b26\u4e2a\u6570\u8d70\u7684\u3002<\/p>\n<p>\u5982\u679c\u8f93\u5165\u6846\u663e\u793a\u7684\u662f 13:14\uff0c\u5219\u8f93\u5165\u6846\u7684\u5bbd\u5ea6\u662f 13:14 \u5916\u52a0\u4e00\u4e2a\u56fe\u6807\u5c3a\u5bf8\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202103\/input-time-icon.png\" width=\"94\" height=\"41\" alt=\"\u8f93\u5165\u6846UI\u793a\u610f\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u5982\u679c\u8f93\u5165\u6846\u663e\u793a\u7684\u662f \u4e0b\u5348 01:14\uff0c\u5219\u8f93\u5165\u6846\u7684\u5bbd\u5ea6\u662f\u5b57\u7b26\u201c\u4e0b\u5348 01:14\u201d\u5bbd\u5ea6\u5916\u52a0\u4e00\u4e2a\u56fe\u6807\u5c3a\u5bf8\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202103\/input-time-icon2.png\" width=\"112\" height=\"30\" alt=\"12\u5c0f\u65f6\u8868\u793a\u7684\u8f93\u5165\u6846\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u7531\u4e8e\u5b57\u7b26\u4e2a\u6570\u4e0d\u540c\uff0c\u56e0\u6b64\uff0c\u5f53\u6539\u53d8\u8f93\u5165\u6846\u7684\u5b57\u53f7\u5927\u5c0f\u4e4b\u540e\uff0c\u8f93\u5165\u6846\u7684\u5c3a\u5bf8\u53d8\u5316\u4e5f\u4f1a\u6709\u6240\u4e0d\u540c\u3002<\/p>\n<p>\u4f8b\u5982\u6587\u5b57\u4ece20px -> 30px\uff0c\u52195\u4e2a\u5b57\u7b26\u53d8\u5316\u7684\u5bbd\u5ea6\u663e\u7136\u8981\u6bd47\u4e2a\u5b57\u7b26\u53d8\u5316\u7684\u5bbd\u5ea6\u5c0f\u3002<\/p>\n<p>\u4e8e\u662f\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u6839\u636e\u524d\u540e\u8f93\u5165\u6846\u5c3a\u5bf8\u53d8\u5316\u5927\u5c0f\u9884\u4f30\u8f93\u5165\u6846\u5185\u5b57\u7b26\u7684\u4e2a\u6570\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u80fd\u77e5\u9053\u8f93\u5165\u6846\u662f24\u5c0f\u65f6\u8868\u793a\u7684\uff0c\u8fd8\u662f12\u5c0f\u65f6\u8868\u793a\u7684\u4e86\u3002<\/p>\n<p>\u57fa\u4e8e\u4e0a\u9762\u539f\u7406\uff0c\u5199\u4e86\u4e2a\u5224\u65ad\u65b9\u6cd5\uff1a<\/p>\n<pre><span style=\"color:green;\">\/\/ \u9ed8\u8ba4\u662f24\u5c0f\u65f6\u7c7b\u578b\uff0c\u4e0d\u652f\u6301time\u7c7b\u578b\u8f93\u5165\u6846\u7684\u6d4f\u89c8\u5668\u4f1a\u4f7f\u7528\u6b64\u7c7b\u578b\uff0c\u4f8b\u5982Safari<\/span>\r\nlet datetimeformat = 'H:mm';\r\n<span style=\"color:green;\">\/\/ \u6839\u636e\u5c3a\u5bf8\u5224\u65ad<\/span>\r\nlet eleInputTmp = document.createElement('input');\r\neleInputTmp.setAttribute('type', 'time');\r\neleInputTmp.value = '00:00';\r\ndocument.body.append(eleInputTmp);\r\n<span style=\"color:green;\">\/\/ \u9ed8\u8ba4\u4e0d\u53ef\u89c1<\/span>\r\neleInputTmp.style.position = 'absolute';\r\neleInputTmp.style.left = '-999px';\r\neleInputTmp.style.fontFamily = 'revert';\r\n<span style=\"color:green;\">\/\/ \u5982\u679c\u6d4f\u89c8\u5668\u4e0d\u652f\u6301time\u7c7b\u578b\u8f93\u5165\u6846\uff0c\u4f8b\u5982Safari\uff0c\u5219\u4f7f\u7528H:mm\u683c\u5f0f<\/span>\r\nif (eleInputTmp.type == 'time') {\r\n    eleInputTmp.style.fontSize = '20px';\r\n    <span style=\"color:green;\">\/\/ \u83b7\u53d6\u6b64\u65f6\u8f93\u5165\u6846\u7684\u5c3a\u5bf8<\/span>\r\n    let numWidthOrigin = eleInputTmp.clientWidth;\r\n    <span style=\"color:green;\">\/\/ \u4fee\u6539\u5c3a\u5bf8<\/span>\r\n    eleInputTmp.style.fontSize = '30px';\r\n    <span style=\"color:green;\">\/\/ \u6bd4\u8f83\u524d\u540e\u5c3a\u5bf8\u53d8\u5316\u7684\u5dee\u5f02<\/span>\r\n    let numDiffWidth = eleInputTmp.clientWidth - numWidthOrigin;\r\n    <span style=\"color:green;\">\/\/ \u53ef\u4ee5\u5224\u65ad\u8f93\u5165\u6846\u5b57\u7b26\u4e2a\u6570<\/span>\r\n    let numLetters = Math.ceil(numDiffWidth \/ 10);\r\n    if (numLetters &amp;gt;= 5) {\r\n        datetimeformat = 'ah:mm';\r\n    }\r\n    eleInputTmp.remove();\r\n}<\/pre>\n<p><code>datetimeformat<\/code>\u5c31\u662f\u6700\u7ec8\u5224\u65ad\u7684\u65f6\u95f4\u8868\u793a\u683c\u5f0f\u3002<\/p>\n<p>\u5f53\u524d\u540e\u53d8\u5316\u5c3a\u5bf8\u4e0d\u5c0f\u4e8e5\u4e2a\u5b57\u7b26\u5bbd\u5ea6\u7684\u65f6\u5019\uff0c\u5219\u8ba4\u4e3a\u662f12\u5c0f\u65f6\u8868\u793a\u6cd5\u3002\u6b64\u65f6\uff0cUI\u7ec4\u4ef6\u5c31\u53ef\u4ee5\u4ee512\u5c0f\u65f6\u8868\u793a\u6cd5\u7684\u6392\u7248\u8bbe\u8ba1\u4ea4\u4e92\u6548\u679c\u4e86\uff0c\u5426\u5219\u4f7f\u752824\u5c0f\u65f6\u8868\u793a\u6cd5\u3002<\/p>\n<p>\u6700\u7ec8\u5b9e\u73b0\u6548\u679c\u9884\u89c8\uff0cSafari\u6d4f\u89c8\u5668\uff0c\u4ee5\u53caWindows Chrome\u6d4f\u89c8\u5668\u4e0b\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202103\/input-time-24.png\" width=\"113\" height=\"365\" alt=\"24\u5c0f\u65f6\u8868\u793a\" class=\"alignnone size-medium\" \/><\/p>\n<p>Firefox\u6d4f\u89c8\u5668\u4e0b\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202103\/input-time-12.png\" width=\"176\" height=\"371\" alt=\"Firefox\u4e0b\u7684UI\u7ec4\u4ef6\u7f8e\u5316\u6548\u679c\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u8fd9\u6837\uff0c\u7f8e\u5316\u7684UI\u4ea4\u4e92\u5c31\u53ef\u4ee5\u548c\u6d4f\u89c8\u5668\u539f\u751f\u884c\u4e3a\u4fdd\u6301\u4e00\u81f4\u4e86\u3002<\/p>\n<h3>\u56db\u3001step\u5c5e\u6027\u4e0e\u5206\u79d2\u9009\u62e9\u7684\u7ec6\u8282<\/h3>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0ctime\u7c7b\u578b\u7684\u8f93\u5165\u6846\u53ea\u80fd\u9009\u62e9\u5230\u5206\u949f\uff0c\u5982\u679c\u60f3\u8981\u79d2\u4e5f\u80fd\u9009\u62e9\uff0c\u6709\u4e0b\u97622\u4e2a\u65b9\u6cd5\u3002<\/p>\n<p><strong>1. \u8bbe\u7f6e\u521d\u59cb\u503c\u662f00:00:00\u683c\u5f0f<\/strong><\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;input type=\"time\" value=\"13:14:20\"&gt;<\/pre>\n<p>\u5219\u79d2\u7684\u503c\u5c31\u4f1a\u663e\u793a\u51fa\u6765\u3002<\/p>\n<p>\u4f8b\u5982windows\u7cfb\u7edf\u4e0b\u7684Chrome\u6d4f\u89c8\u5668\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202103\/2021-03-30_235210.png\" width=\"110\" height=\"39\" alt=\"\u79d2\u4e5f\u80fd\u663e\u793a\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4ece\u4e0a\u56fe\u53ef\u4ee5\u770b\u51fa\uff0c\u867d\u7136\u79d2\u51fa\u73b0\u4e86\uff0c\u4f46\u662f\u662f\u7f6e\u7070\u7684\uff0c\u539f\u56e0\u662f\u6b64\u65f6\u7684step\u662f\u6309\u716760\u6765\u6e32\u67d3\u7684\u3002<\/p>\n<p>\u8fd9\u5c31\u5f15\u51fa\u4e0b\u4e00\u4e2a\u8bbe\u7f6e\u79d2\u9009\u62e9\u7684\u65b9\u6cd5\u3002<\/p>\n<p><strong>2. \u8bbe\u7f6e\u5408\u9002\u7684step\u503c<\/strong><\/p>\n<p>time\u7c7b\u578b\u7684\u8f93\u5165\u6846\uff0c\u53ea\u8981step\u7684\u503c\u4e0d\u662f60\u7684\u500d\u6570\uff0c\u5219\u5982\u679cvalue\u521d\u59cb\u503c\u662f\u4ec0\u4e48\uff0c\u4e00\u5b9a\u4f1a\u7cbe\u786e\u5230\u79d2\u8fdb\u884c\u663e\u793a\u3002<\/p>\n<p>\u4f8b\u5982\u4e0b\u9762\u7684HTML\u4ee3\u7801\uff1a<\/p>\n<pre>&lt;p&gt;&lt;input type=\"time\" step=\"1\"&gt;&lt;\/p&gt;\r\n&lt;p&gt;&lt;input type=\"time\" value=\"13:14\" step=\"1\"&gt;&lt;\/p&gt;\r\n&lt;p&gt;&lt;input type=\"time\" step=\"20\"&gt;&lt;\/p&gt;\r\n&lt;p&gt;&lt;input type=\"time\" value=\"13:14\" step=\"20\"&gt;&lt;\/p&gt;\r\n&lt;p&gt;&lt;input type=\"time\" step=\"61\"&gt;&lt;\/p&gt;\r\n&lt;p&gt;&lt;input type=\"time\" step=\"9999999\"&gt;&lt;\/p&gt;<\/pre>\n<p>\u6700\u7ec8\u5168\u90e8\u90fd\u662f\u53ef\u4ee5\u9009\u62e9\u5230\u79d2\u3002<\/p>\n<p>\u5982\u4e0b\u622a\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202103\/2021-03-30_235844.png\" width=\"112\" height=\"245\" alt=\"\u79d2\u7684\u663e\u793a\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4f46\u662f\u5982\u679cstep\u5c5e\u6027\u503c\u662f60\u7684\u500d\u6570\uff0c\u5219\u6b64\u65f6step\u4f1a\u8ba4\u4e3a\u662f\u5206\u949f\uff0c\u6b64\u65f6\uff0c\u5982\u679cvalue\u7684\u503c\u4e0d\u662f00:00:00\u683c\u5f0f\uff0c\u5219\u65f6\u95f4\u7684\u9009\u62e9\u4f1a\u7cbe\u786e\u5230\u5206\u949f\uff1b\u5982\u679cvalue\u7684\u503c\u662f00:00:00\u683c\u5f0f\uff0c\u5219\u79d2\u9ed8\u8ba4\u7f6e\u7070\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;p&gt;&lt;input type=\"time\" step=\"60\"&gt;&lt;\/p&gt;\r\n&lt;p&gt;&lt;input type=\"time\" value=\"13:14\" step=\"120\"&gt;&lt;\/p&gt;<\/pre>\n<p>\u5219\u6e32\u67d3\u6548\u679c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202103\/2021-03-31_000236.png\" width=\"82\" height=\"74\" alt=\"step\u662f60\u500d\u6570\u7684\u65f6\u5019\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u56e0\u6b64\uff0c\u8981\u60f3<code>value=\"13:14:20\"<\/code>\u8bbe\u7f6e\u540e\u79d2\u7684\u503c20\u4e0d\u7f6e\u7070\uff0c\u53ea\u9700\u8981\u8bbe\u7f6estep\u5c5e\u6027\u503c\u4e3a1\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<pre>&lt;input type=\"time\" value=\"13:14:20\" step=\"1\"&gt;<\/pre>\n<p>\u6b64\u65f6\uff0c\u540e\u9762\u768420\u5c31\u4e0d\u662f\u7070\u8272\u7684\u4e86\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202103\/2021-03-31_000557.png\" width=\"107\" height=\"77\" alt=\"20\u4e0d\u662f\u7070\u8272\" class=\"alignnone size-medium\" \/><\/p>\n<h4>step\u4e0d\u5f71\u54cdvalue\u503c\u7684\u8bbe\u7f6e<\/h4>\n<p>step\u867d\u7136\u8bed\u4e49\u4e0a\u8868\u793a\u65f6\u95f4\u7684\u95f4\u9694\uff0c\u4f46\u662f\u884c\u4e3a\u4e0a\u5e76\u6ca1\u6709\u963b\u6b62value\u7684\u8bbe\u7f6e\uff0c\u4ec0\u4e48\u610f\u601d\u5462\uff1f<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>&lt;input type=\"time\" step=\"30\"&gt;<\/pre>\n<p>\u8868\u793a\u79d2\u7684\u6b65\u9636\u662f30\u79d2\uff0c\u4e5f\u5373\u662f00:00:00\u6216\u800500:00:30\u624d\u662f\u5408\u6cd5\u7684\u503c\uff0c\u4f46\u662f\uff0c\u5b9e\u9645\u4e0a\uff0c\u4f60\u4e0b\u62c9\u5217\u8868\u9009\u62e900:00:20\u4e5f\u662f\u53ef\u4ee5\u7684\uff0cstep\u9650\u5236\u7684\u662f\u4e0a\u4e0b\u952e\u5feb\u6377\u9009\u62e9\u65f6\u5019\u7684\u503c\uff0c\u5e76\u6ca1\u6709\u9650\u5236\u70b9\u51fb\u884c\u4e3a\uff0c\u4ee5\u53ca\u76f4\u63a5\u4f7f\u7528value\u8d4b\u503c\u7684\u9650\u5236\u3002<\/p>\n<p>\u8fd9\u662fstep\u7684\u53e6\u5916\u4e00\u4e2a\u7ec6\u8282\u77e5\u8bc6\u3002<\/p>\n<h3>\u4e94\u3001\u5176\u4ed6\u7ec6\u8282\u3001\u79fb\u52a8\u7aef\u3001\u7ed3\u8bed<\/h3>\n<p><strong>\u5176\u4ed6\u7ec6\u8282<\/strong><\/p>\n<ul>\n<li>\u65e0\u8bba\u662fvalue\u5c5e\u6027\u8bbe\u7f6e\u7684\u503c\uff0c\u8fd8\u662f step\/min\/max\u5c5e\u6027\u8bbe\u7f6e\u7684\u503c\uff0c\u90fd\u5fc5\u987b\u662f\u4e25\u683c\u768400:00\u6216\u800500:00:00\u683c\u5f0f\uff0c\u4e5f\u5c31\u662f\u524d\u9762\u76840\u5fc5\u987b\u8865\u5168\uff0c\u4f8b\u5982\u4e0b\u9762\u7684HTML\u4e2d\u7684value\u8bbe\u7f6e\u5c31\u662f\u65e0\u6548\u7684\uff1a\n<p>&lt;p&gt;&lt;input type=&#8221;time&#8221; value=&#8221;3:14&#8243;&gt;&lt;\/p&gt;<\/p>\n<p>\u6e32\u67d3\u51fa\u6765\u7684\u5c31\u662f4\u4e2a\u77ed\u6a2a\u7ebf\uff08\u5982\u4e0b\u56fe\u6548\u679c\uff09\uff0cvalue\u503c\u5fc5\u987b\u5199\u6210 <code>value=\"03:14\"<\/code> \u624d\u53ef\u4ee5\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202103\/2021-03-31_002002.png\" width=\"86\" height=\"36\" alt=\"4\u4e2a\u77ed\u6a2a\u7ebf\u793a\u610f\" class=\"alignnone size-medium\" \/><\/li>\n<li>min\/max\u5c5e\u6027\u548cstep\u5c5e\u6027\u4e00\u6837\uff0c\u53ea\u80fd\u5f71\u54cd\u4e0a\u4e0b\u952e\u8fd9\u6837\u7684\u5feb\u6377\u952e\u9009\u62e9\uff0c\u5e76\u4e0d\u80fd\u963b\u6b62\u70b9\u51fb\u9009\u62e9\u4e0d\u518d\u9650\u5236\u8303\u56f4\u4e2d\u7684\u503c\u3002<\/li>\n<li>Chrome\u6d4f\u89c8\u5668\u66b4\u9732\u4e86\u5f88\u591a\u4f2a\u5143\u7d20\uff0c\u53ef\u4ee5\u7528\u6765\u4fee\u6539\u9ed8\u8ba4\u7684\u65f6\u95f4\u9009\u62e9\u63a7\u4ef6\u7684\u6837\u5f0f\u7ec6\u8282\uff0c\u4f8b\u5982<code>::-webkit-datetime-edit<\/code>\u3001<code>::-webkit-datetime-edit-fields-wrapper<\/code>\u3001<code>::-webkit-datetime-edit-hour-field<\/code>\u3001<code>::-webkit-datetime-edit-text <\/code>\u3001<code>::-webkit-datetime-edit-minute-field<\/code>\u7b49\u3002<\/li>\n<\/ul>\n<p><strong>\u79fb\u52a8\u7aef<\/strong><\/p>\n<p>\u5728\u79fb\u52a8\u7aef\uff0c\u5bf9\u4e8e\u65f6\u95f4\u9009\u62e9\u8f93\u5165\u6846\uff0c\u8bbe\u5907\u4f1a\u5728\u7cfb\u7edf\u5c42\u9762\u5b9e\u73b0\u66f4\u5229\u4e8e\u79fb\u52a8\u7aef\u4ea4\u4e92\u7684\u6548\u679c\uff0c\u6211\u4e2a\u4eba\u7684\u5efa\u8bae\u662f\u53ef\u4ee5\u4e0d\u505aUI\u7684\u7f8e\u5316\u5904\u7406\u7684\uff0c\u4f8b\u5982\u5728iOS\u7cfb\u7edf\u4e0b\uff0c\u663e\u793a\u7684\u65f6\u95f4\u9009\u62e9\u5217\u8868\u548ciOS\u7684\u65f6\u95f4\u9009\u62e9\u7684UI\u548c\u4ea4\u4e92\u662f\u4e00\u8109\u76f8\u627f\u7684\uff0c\u6548\u679c\u66f4\u597d\u3002<\/p>\n<p>\u4e0d\u8fc7\uff0c\u79fb\u52a8\u7aef\u4e5f\u6709\u5176\u4ed6\u7684\u5c0f\u7455\u75b5\uff0c\u6309\u7167\u6211\u4e4b\u524d\u5f00\u53d1\u7684\u7ecf\u9a8c\uff0c\u5728iOS Safari\u6d4f\u89c8\u5668\u4e0b\uff0cmin max\u5c5e\u6027\u4f3c\u4e4e\u4e0d\u80fd\u5bf9\u8303\u56f4\u8fdb\u884c\u9650\u5236\u3002<\/p>\n<p>\u8fd9\u5c31\u5bfc\u81f4\u6700\u7ec8\u8868\u5355\u6570\u636e\u63d0\u4ea4\u7684\u65f6\u5019\uff0c\u9700\u8981\u505a\u4e0b\u9a8c\u8bc1\u3002<\/p>\n<h4>\u7ed3\u8bed<\/h4>\n<p>\u5b66\u4e60\u5c0f\u5929\u5730\uff0c\u8bb0\u5f55\u4e0b\u8fd1\u671f\u5b66\u5230\u7684\u4e9b\u4e1c\u897f\uff0c\u4e00\u6765\u5907\u5fd8\uff0c\u4e8c\u6765\u53ef\u80fd\u53ef\u4ee5\u5e2e\u5230\u6709\u9700\u8981\u7684\u4eba\u3002<\/p>\n<p>\u611f\u8c22\u60a8\u7684\u9605\u8bfb\u4e0e\u652f\u6301\uff0c\u6bd4\u5fc3\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/emtion\/emoji\/2764.svg\" width=\"20\" height=\"20\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u6b22\u8fce\u5206\u4eab\uff0c\u52ff\u5168\u6587\u8f6c\u8f7d\uff0c\u5982\u679c\u5b9e\u5728\u559c\u6b22\uff0c\u53ef\u6536\u85cf\uff0c\u6c38\u4e0d\u8fc7\u671f\uff0c\u4e14\u4f1a\u53ca\u65f6\u66f4\u65b0\u77e5\u8bc6\u70b9\u53ca\u4fee\u6b63\u9519\u8bef\uff0c\u9605\u8bfb\u4f53\u9a8c\u4e5f\u66f4\u597d\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=9906\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=9906<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/image.zhangxinxu.com\/image\/blog\/202103\/input-cloud-cover.jpg\" width=\"160\" height=\"101\" alt=\"\u7a7a\u4e2d\u9493\u9c7c-\u5360\u4f4d\u56fe\" class=\"alignright size-medium\" loading=\"lazy\" \/><\/p>\n<p>\u6700\u8fd1\u4e0etype=&#8221;time&#8221;\u8f93\u5165\u6846\u6253\u4e86\u4e0d\u5c11\u4ea4\u9053\uff0c\u5b66\u5230\u4e86\u4e0d\u5c11\u7ec6\u8282\u77e5\u8bc6\uff0c\u5173\u4e8eUI\uff0c\u5173\u4e8e\u65f6\u95f4\u683c\u5f0f\uff0c\u4ee5\u53castep\/min\/max\u5c5e\u6027\uff0c\u548c\u5927\u5bb6\u5206\u4eab\u4e0b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1097],"tags":[63,607,9,37,1746,1594,765,1534,763],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/9906"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=9906"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/9906\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=9906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=9906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=9906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}