{"id":3168,"date":"2024-11-10T13:43:55","date_gmt":"2024-11-10T05:43:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3168\/"},"modified":"2024-11-10T13:43:55","modified_gmt":"2024-11-10T05:43:55","slug":"js%e5%a6%82%e4%bd%95%e4%bc%a0%e9%80%92%e5%8f%82%e6%95%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3168\/","title":{"rendered":"js\u5982\u4f55\u4f20\u9012\u53c2\u6570"},"content":{"rendered":"<blockquote><p>\n  javascript \u4e2d\u4f20\u9012\u53c2\u6570\u6709\u4e94\u79cd\u65b9\u5f0f\uff1a\u51fd\u6570\u53c2\u6570url \u67e5\u8be2\u5b57\u7b26\u4e32ajax \u8bf7\u6c42html \u8868\u5355localstorage\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110806010654225.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u4f20\u9012\u53c2\u6570\u63d2\u56fe\" alt=\"js\u5982\u4f55\u4f20\u9012\u53c2\u6570\u63d2\u56fe\" \/><\/p>\n<p><strong>\u7528 JavaScript \u4f20\u9012\u53c2\u6570<\/strong><\/p>\n<p>JavaScript \u4e2d\u4f20\u9012\u53c2\u6570\u6709\u4ee5\u4e0b\u51e0\u79cd\u4e3b\u8981\u65b9\u5f0f\uff1a<\/p>\n<p><strong>1. \u51fd\u6570\u53c2\u6570<\/strong><\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>function myFunction(param1, param2, ...) {\n  \/\/ \u51fd\u6570\u4f53\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u8c03\u7528\uff1a<\/strong><\/p>\n<pre>myFunction(\"param1 \u503c\", \"param2 \u503c\", ...);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>2. URL \u67e5\u8be2\u5b57\u7b26\u4e32<\/strong><\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>const url = \"example.com?param1=value1&amp;param2=value2\";<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u8bbf\u95ee\uff1a<\/strong><\/p>\n<pre>window.location.search \/\/ \"param1=value1&amp;param2=value2\"<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>3. AJAX \u8bf7\u6c42<\/strong><\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>const data = { param1: \"value1\", param2: \"value2\" };\n\nfetch(\"example.com\", {\n  method: \"POST\",\n  body: JSON.stringify(data),\n});<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u8bbf\u95ee\uff1a<\/strong><\/p>\n<pre>const responseObject = await response.json();\nresponseObject.param1 \/\/ \"value1\"\nresponseObject.param2 \/\/ \"value2\"<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>4. HTML \u8868\u5355<\/strong><\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>&lt;form action=\"example.com\" method=\"POST\"&gt;\n  &lt;input type=\"text\" name=\"param1\" value=\"value1\"&gt;\n  &lt;input type=\"text\" name=\"param2\" value=\"value2\"&gt;\n  &lt;input type=\"submit\"&gt;\n&lt;\/form&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u8bbf\u95ee\uff1a<\/strong><\/p>\n<pre>const formData = new FormData(document.querySelector(\"form\"));\nformData.get(\"param1\") \/\/ \"value1\"\nformData.get(\"param2\") \/\/ \"value2\"<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>5. localStorage<\/strong><\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>localStorage.setItem(\"param1\", \"value1\");\nlocalStorage.setItem(\"param2\", \"value2\");<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u8bbf\u95ee\uff1a<\/strong><\/p>\n<pre>localStorage.getItem(\"param1\") \/\/ \"value1\"\n localStorage.getItem(\"param2\") \/\/ \"value2\"<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjs\u5982\u4f55\u4f20\u9012\u53c2\u6570\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>javascript \u4e2d\u4f20\u9012\u53c2\u6570\u6709\u4e94\u79cd\u65b9\u5f0f\uff1a\u51fd\u6570\u53c2\u6570url \u67e5\u8be2\u5b57\u7b26\u4e32ajax \u8bf7\u6c42html \u8868\u5355localstorage \u7528 JavaScript \u4f20\u9012\u53c2\u6570 JavaScript \u4e2d\u4f20\u9012\u53c2\u6570\u6709\u4ee5\u4e0b\u51e0\u79cd\u4e3b\u8981\u65b9\u5f0f\uff1a 1. \u51fd\u6570\u53c2\u6570 \u8bed\u6cd5\uff1a function myFunction(param1, param2, &#8230;) { \/\/ \u51fd\u6570\u4f53 } \u767b\u5f55\u540e\u590d\u5236 \u8c03\u7528\uff1a myFunction(&#8220;param1 \u503c&#8221;, &#8220;param2 \u503c&#8221;, &#8230;); \u767b\u5f55\u540e\u590d\u5236 2. URL \u67e5\u8be2\u5b57\u7b26\u4e32 \u8bed\u6cd5\uff1a const url = &#8220;example.com?param1=value1&amp;param2=value2&#8221;; \u767b\u5f55\u540e\u590d\u5236 \u8bbf\u95ee\uff1a window.location.search \/\/ &#8220;param1=value1&amp;param2=value2&#8221; \u767b\u5f55\u540e\u590d\u5236 3. AJAX \u8bf7\u6c42 \u8bed\u6cd5\uff1a const data = { param1: &#8220;value1&#8221;, param2: &#8220;value2&#8221; [&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-3168","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3168","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=3168"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3168\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}