{"id":3287,"date":"2024-11-10T16:27:41","date_gmt":"2024-11-10T08:27:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3287\/"},"modified":"2024-11-10T16:27:41","modified_gmt":"2024-11-10T08:27:41","slug":"js%e5%a6%82%e4%bd%95%e8%a7%a6%e5%8f%91date","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3287\/","title":{"rendered":"js\u5982\u4f55\u89e6\u53d1date"},"content":{"rendered":"<blockquote><p>\n  \u4f7f\u7528 javascript \u89e6\u53d1\u65e5\u671f\u9009\u62e9\u5668\u6709\u56db\u79cd\u65b9\u6cd5\uff1a1\uff09\u76f4\u63a5\u89e6\u53d1 .click() \u65b9\u6cd5\uff1b2\uff09\u663e\u793a\u9690\u85cf\u7684\u65e5\u671f\u9009\u62e9\u5668 .show() \u65b9\u6cd5\uff1b3\uff09\u5c06\u7126\u70b9\u7f6e\u4e8e\u65e5\u671f\u9009\u62e9\u5668 .focus() \u65b9\u6cd5\uff1b4\uff09\u4f7f\u7528 dispatchevent() \u65b9\u6cd5\u89e6\u53d1 focus \u4e8b\u4ef6\u3002\u7b2c\u4e09\u65b9\u5e93\uff0c\u5982 jquery datepicker\u3001bootstrap datepicker \u548c flatpickr\uff0c\u4e5f\u53ef\u4ee5\u7b80\u5316\u6b64\u4efb\u52a1\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110809061533003.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u89e6\u53d1date\u63d2\u56fe\" alt=\"js\u5982\u4f55\u89e6\u53d1date\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 JavaScript \u89e6\u53d1\u65e5\u671f\u9009\u62e9\u5668<\/strong><\/p>\n<p><strong>\u76f4\u63a5\u6253\u5f00\u65e5\u671f\u9009\u62e9\u5668<\/strong><\/p>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 .click() \u65b9\u6cd5\u76f4\u63a5\u89e6\u53d1\u65e5\u671f\u9009\u62e9\u5668\uff1a<\/p>\n<pre>document.getElementById(\"datepicker\").click();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 show() \u65b9\u6cd5<\/strong><\/p>\n<p>show() \u65b9\u6cd5\u4f1a\u663e\u793a\u4e00\u4e2a\u9690\u85cf\u7684\u65e5\u671f\u9009\u62e9\u5668\uff1a<\/p>\n<pre>document.getElementById(\"datepicker\").show();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 focus() \u65b9\u6cd5<\/strong><\/p>\n<p>focus() \u65b9\u6cd5\u4f1a\u5c06\u7126\u70b9\u7f6e\u4e8e\u65e5\u671f\u9009\u62e9\u5668\u4e0a\uff0c\u8fd9\u4e5f\u4f1a\u89e6\u53d1\u5b83\uff1a<\/p>\n<pre>document.getElementById(\"datepicker\").focus();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 dispatchEvent() \u65b9\u6cd5<\/strong><\/p>\n<p>dispatchEvent() \u65b9\u6cd5\u53ef\u4ee5\u89e6\u53d1\u4e00\u4e2a\u7279\u5b9a\u7684\u4e8b\u4ef6\uff0c\u5305\u62ec\u65e5\u671f\u9009\u62e9\u5668\u7684 focus \u4e8b\u4ef6\uff1a<\/p>\n<pre>var event = new Event(\"focus\");\ndocument.getElementById(\"datepicker\").dispatchEvent(event);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<\/strong><\/p>\n<p>\u6709\u8bb8\u591a JavaScript \u5e93\u53ef\u4ee5 \u0443\u043f\u0440\u043e\u0441\u0438\u0442\u044c\u89e6\u53d1\u65e5\u671f\u9009\u62e9\u5668\u7684\u4efb\u52a1\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>[jQuery Datepicker](https:\/\/jqueryui.com\/datepicker\/)<\/li>\n<li>[Bootstrap Datepicker](https:\/\/-datepicker.readthedocs.io\/en\/latest\/)<\/li>\n<li>[Flatpickr](https:\/\/flatpickr.js.org\/)<\/li>\n<\/ul>\n<p>\u4f7f\u7528\u8fd9\u4e9b\u5e93\u65f6\uff0c\u8bf7\u9075\u5faa\u5176\u7279\u5b9a\u7684\u6587\u6863\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjs\u5982\u4f55\u89e6\u53d1date\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 javascript \u89e6\u53d1\u65e5\u671f\u9009\u62e9\u5668\u6709\u56db\u79cd\u65b9\u6cd5\uff1a1\uff09\u76f4\u63a5\u89e6\u53d1 .click() \u65b9\u6cd5\uff1b2\uff09\u663e\u793a\u9690\u85cf\u7684\u65e5\u671f\u9009\u62e9\u5668 .show() \u65b9\u6cd5\uff1b3\uff09\u5c06\u7126\u70b9\u7f6e\u4e8e\u65e5\u671f\u9009\u62e9\u5668 .focus() \u65b9\u6cd5\uff1b4\uff09\u4f7f\u7528 dispatchevent() \u65b9\u6cd5\u89e6\u53d1 focus \u4e8b\u4ef6\u3002\u7b2c\u4e09\u65b9\u5e93\uff0c\u5982 jquery datepicker\u3001bootstrap datepicker \u548c flatpickr\uff0c\u4e5f\u53ef\u4ee5\u7b80\u5316\u6b64\u4efb\u52a1\u3002 \u5982\u4f55\u4f7f\u7528 JavaScript \u89e6\u53d1\u65e5\u671f\u9009\u62e9\u5668 \u76f4\u63a5\u6253\u5f00\u65e5\u671f\u9009\u62e9\u5668 \u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 .click() \u65b9\u6cd5\u76f4\u63a5\u89e6\u53d1\u65e5\u671f\u9009\u62e9\u5668\uff1a document.getElementById(&#8220;datepicker&#8221;).click(); \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 show() \u65b9\u6cd5 show() \u65b9\u6cd5\u4f1a\u663e\u793a\u4e00\u4e2a\u9690\u85cf\u7684\u65e5\u671f\u9009\u62e9\u5668\uff1a document.getElementById(&#8220;datepicker&#8221;).show(); \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 focus() \u65b9\u6cd5 focus() \u65b9\u6cd5\u4f1a\u5c06\u7126\u70b9\u7f6e\u4e8e\u65e5\u671f\u9009\u62e9\u5668\u4e0a\uff0c\u8fd9\u4e5f\u4f1a\u89e6\u53d1\u5b83\uff1a document.getElementById(&#8220;datepicker&#8221;).focus(); \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 dispatchEvent() \u65b9\u6cd5 dispatchEvent() \u65b9\u6cd5\u53ef\u4ee5\u89e6\u53d1\u4e00\u4e2a\u7279\u5b9a\u7684\u4e8b\u4ef6\uff0c\u5305\u62ec\u65e5\u671f\u9009\u62e9\u5668\u7684 focus \u4e8b\u4ef6\uff1a var event = new Event(&#8220;focus&#8221;); document.getElementById(&#8220;datepicker&#8221;).dispatchEvent(event); \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3287","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3287"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3287\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}