{"id":854,"date":"2025-12-22T09:02:17","date_gmt":"2025-12-22T01:02:17","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=854"},"modified":"2025-12-22T09:02:17","modified_gmt":"2025-12-22T01:02:17","slug":"javascriptvoid-0%e7%94%a8%e6%b3%95%e5%8f%8a%e5%b8%b8%e8%a7%81%e9%97%ae%e9%a2%98%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/22\/javascriptvoid-0%e7%94%a8%e6%b3%95%e5%8f%8a%e5%b8%b8%e8%a7%81%e9%97%ae%e9%a2%98%e8%a7%a3%e6%9e%90\/","title":{"rendered":"javascript:void (0)\u7528\u6cd5\u53ca\u5e38\u89c1\u95ee\u9898\u89e3\u6790"},"content":{"rendered":"\n<p>JavaScript \u4e2d javascript:void(0) \u7684\u7528\u6cd5\u53ca\u5e38\u89c1\u95ee\u9898\u8be6\u89e3javascript:void(0) \u662f HTML \u4e2d\u4e00\u79cd\u5e38\u89c1\u7684\u4f2a\u534f\u8bae\uff0c\u5e38\u7528\u4e8e &lt;a&gt; \u6807\u7b7e\u7684 href \u5c5e\u6027\uff0c\u76ee\u7684\u662f\u963b\u6b62\u9ed8\u8ba4\u7684\u9875\u9762\u8df3\u8f6c\u884c\u4e3a\uff0c\u540c\u65f6\u4fdd\u6301\u94fe\u63a5\u7684\u5916\u89c2\uff08\u9f20\u6807\u60ac\u505c\u65f6\u663e\u793a\u5c0f\u624b\u5149\u6807\uff09\u30021. \u57fa\u672c\u7528\u6cd5<\/p>\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;!-- \u7ecf\u5178\u5199\u6cd5\uff1a\u70b9\u51fb\u65e0\u4efb\u4f55\u53cd\u5e94 --&gt;\n&amp;lt;a href=&quot;javascript:void(0)&quot;&gt;\u70b9\u51fb\u6211&amp;lt;\/a&gt;\n\n&amp;lt;!-- \u5e26\u4e8b\u4ef6\u5904\u7406 --&gt;\n&amp;lt;a href=&quot;javascript:void(0)&quot; onclick=&quot;alert(&#039;Hello&#039;)&quot;&gt;\u70b9\u51fb\u6211&amp;lt;\/a&gt;\n\n&amp;lt;!-- \u6216\u8005\u66f4\u5e38\u89c1\u7684\u73b0\u4ee3\u5199\u6cd5 --&gt;\n&amp;lt;a href=&quot;javascript:void(0)&quot; onclick=&quot;doSomething()&quot;&gt;\u70b9\u51fb\u6211&amp;lt;\/a&gt;\n<\/pre><\/div>\n\n\n<p>\u4f5c\u7528\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>href=&#8221;javascript:void(0)&#8221; \u544a\u8bc9\u6d4f\u89c8\u5668\u6267\u884c\u4e00\u6bb5 JavaScript \u4ee3\u7801<\/li>\n\n\n\n<li>void(0) \u662f JavaScript \u7684 void \u8fd0\u7b97\u7b26\uff0c\u5b83\u603b\u662f\u8fd4\u56de undefined<\/li>\n\n\n\n<li>\u6d4f\u89c8\u5668\u6267\u884c\u540e\u5f97\u5230 undefined\uff0c\u4e8e\u662f\u4e0d\u6267\u884c\u4efb\u4f55\u8df3\u8f6c\uff08\u4e0d\u4f1a\u5237\u65b0\u9875\u9762\u6216\u8df3\u5230\u65b0\u5730\u5740\uff09<\/li>\n<\/ul>\n\n\n\n<p>2. \u4e3a\u4ec0\u4e48\u4e0d\u7528 href=&#8221;#&#8221; \u800c\u7528 javascript:void(0)\uff1f<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>\u5199\u6cd5<\/th><th>\u4f18\u70b9<\/th><th>\u7f3a\u70b9<\/th><th>\u63a8\u8350\u573a\u666f<\/th><\/tr><tr><td>href=&#8221;#&#8221;<\/td><td>\u4ee3\u7801\u6700\u77ed<\/td><td>1. \u4f1a\u8df3\u8f6c\u5230\u9875\u9762\u9876\u90e8\uff08# \u4ee3\u8868\u5f53\u524d\u9875\u9762\u951a\u70b9\uff09 2. \u6539\u53d8 URL\uff08\u6dfb\u52a0 #\uff09 3. \u53ef\u80fd\u89e6\u53d1\u9875\u9762\u6eda\u52a8 4. \u5f71\u54cd\u6d4f\u89c8\u5668\u5386\u53f2\u8bb0\u5f55<\/td><td>\u4ec5\u7528\u4e8e\u7b80\u5355\u951a\u70b9\u8df3\u8f6c<\/td><\/tr><tr><td>href=&#8221;javascript:void(0)&#8221;<\/td><td>\u5b8c\u5168\u963b\u6b62\u8df3\u8f6c\u3001\u4e0d\u6539\u53d8 URL\u3001\u4e0d\u6eda\u52a8\u9875\u9762<\/td><td>1. \u4ee3\u7801\u7a0d\u957f 2. \u8001\u6d4f\u89c8\u5668\u53ef\u80fd\u6709\u8f7b\u5fae\u6027\u80fd\u5f00\u9500\uff08\u6781\u5c11\uff09<\/td><td>\u4f20\u7edf\u6309\u94ae\u5f0f\u94fe\u63a5<\/td><\/tr><tr><td>href=&#8221;###&#8221; \u6216 href=&#8221;###&#8221;<\/td><td>\u51e0\u4e4e\u4e0d\u6eda\u52a8<\/td><td>\u4ecd\u4f1a\u6539\u53d8 URL\uff0c\u5386\u53f2\u8bb0\u5f55\u6709\u5783\u573e<\/td><td>\u4e0d\u63a8\u8350<\/td><\/tr><tr><td>\u73b0\u4ee3\u6700\u4f73\uff1a\u4e0d\u5199 href<\/td><td>\u6700\u5e72\u51c0\u3001\u6700\u8bed\u4e49\u5316<\/td><td>\u5931\u53bb\u9ed8\u8ba4\u201c\u53ef\u70b9\u51fb\u201d\u6837\u5f0f\uff08\u9700 CSS \u6a21\u62df\uff09<\/td><td>\u63a8\u8350\uff08\u89c1\u4e0b\u6587\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>3. \u73b0\u4ee3\u63a8\u8350\u505a\u6cd5\uff082025 \u5e74\u6700\u4f73\u5b9e\u8df5\uff09<\/p>\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;!-- \u65b9\u5f0f1\uff1a\u63a8\u8350 - \u7528 button \u4ee3\u66ff a\uff08\u6700\u8bed\u4e49\u5316\uff09 --&gt;\n&amp;lt;button type=&quot;button&quot; onclick=&quot;doSomething()&quot;&gt;\u70b9\u51fb\u6211&amp;lt;\/button&gt;\n\n&amp;lt;!-- \u65b9\u5f0f2\uff1a\u4ecd\u60f3\u7528 a \u6807\u7b7e\uff0c\u4f46\u4e0d\u5199 href --&gt;\n&amp;lt;a role=&quot;button&quot; tabindex=&quot;0&quot; onclick=&quot;doSomething()&quot;&gt;\u70b9\u51fb\u6211&amp;lt;\/a&gt;\n\n&amp;lt;!-- \u65b9\u5f0f3\uff1a\u7528 CSS \u6a21\u62df\u53ef\u70b9\u51fb\u6837\u5f0f --&gt;\n&amp;lt;a href=&quot;javascript:void(0)&quot; class=&quot;btn-like&quot; onclick=&quot;doSomething()&quot;&gt;\u70b9\u51fb\u6211&amp;lt;\/a&gt;\n\n&amp;lt;style&gt;\n  .btn-like {\n    color: blue;\n    text-decoration: underline;\n    cursor: pointer;\n  }\n  .btn-like:hover {\n    color: #0056b3;\n  }\n&amp;lt;\/style&gt;\n<\/pre><\/div>\n\n\n<p>\u4e3a\u4ec0\u4e48 button \u66f4\u597d\uff1f<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8bed\u4e49\u6b63\u786e\uff08&lt;button> \u5c31\u662f\u6309\u94ae\uff0c&lt;a> \u662f\u94fe\u63a5\uff09<\/li>\n\n\n\n<li>\u65e0\u9700 hack href<\/li>\n\n\n\n<li>\u952e\u76d8\u53ef\u8bbf\u95ee\uff08Enter\/Space \u89e6\u53d1\uff09<\/li>\n\n\n\n<li>\u65e0\u5386\u53f2\u8bb0\u5f55\u6c61\u67d3<\/li>\n\n\n\n<li>\u5c4f\u5e55\u9605\u8bfb\u5668\u53cb\u597d<\/li>\n<\/ul>\n\n\n\n<p>4. \u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6848<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>\u95ee\u9898<\/th><th>\u539f\u56e0<\/th><th>\u89e3\u51b3\u65b9\u6848<\/th><\/tr><tr><td>\u70b9\u51fb\u540e\u9875\u9762\u8df3\u5230\u9876\u90e8<\/td><td>\u4f7f\u7528\u4e86 href=&#8221;#&#8221;<\/td><td>\u6539\u7528 javascript:void(0) \u6216\u79fb\u9664 href + \u7528 button<\/td><\/tr><tr><td>URL \u680f\u51fa\u73b0 # \u6216 javascript:void(0)<\/td><td>\u6d4f\u89c8\u5668\u663e\u793a\u4e86 href \u503c<\/td><td>1. \u7528 button 2. \u7528 onclick + return false\uff08\u89c1\u4e0b\uff09<\/td><\/tr><tr><td>\u4e8b\u4ef6\u4e0d\u89e6\u53d1<\/td><td>\u4e8b\u4ef6\u7ed1\u5b9a\u5199\u9519\u6216 return false \u7f3a\u5931<\/td><td>\u786e\u4fdd onclick \u8fd4\u56de false \u6216\u7528 preventDefault()<\/td><\/tr><tr><td>SEO \u6216\u53ef\u8bbf\u95ee\u6027\u5dee<\/td><td>javascript:void(0) \u672c\u8eab\u65e0\u5b9e\u9645\u94fe\u63a5<\/td><td>\u4f18\u5148\u7528 &lt;button&gt; \u6216 &lt;a href=&#8221;&#8230;&#8221;&gt;\uff08\u771f\u94fe\u63a5\uff09<\/td><\/tr><tr><td>\u5728\u4e25\u683c\u6a21\u5f0f\u4e0b\u62a5\u9519<\/td><td>\u6781\u5c11\u6570\u8001\u4ee3\u7801\u4e2d undefined \u88ab\u91cd\u5199<\/td><td>\u7528 void 0 \u800c\u975e void(0)\uff08\u4e24\u8005\u7b49\u4ef7\uff0c\u4f46 void 0 \u66f4\u5b89\u5168\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u63a8\u8350\u5199\u6cd5\uff08\u517c\u5bb9\u65e7\u9879\u76ee\uff09\uff1a<\/p>\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;a href=&quot;javascript:void(0)&quot; onclick=&quot;doSomething(); return false;&quot;&gt;\u70b9\u51fb\u6211&amp;lt;\/a&gt;\n<\/pre><\/div>\n\n\n<p>\u6216\u66f4\u73b0\u4ee3\uff1a<\/p>\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;a href=&quot;#&quot; onclick=&quot;doSomething(event)&quot;&gt;\u70b9\u51fb\u6211&amp;lt;\/a&gt;\n\n&amp;lt;script&gt;\nfunction doSomething(e) {\n  e.preventDefault();  \/\/ \u963b\u6b62\u9ed8\u8ba4\u884c\u4e3a\n  \/\/ \u4f60\u7684\u4ee3\u7801\n}\n&amp;lt;\/script&gt;\n<\/pre><\/div>\n\n\n<p>5. \u603b\u7ed3\u5bf9\u6bd4\u8868\uff082025 \u5e74\u63a8\u8350\u4f18\u5148\u7ea7\uff09<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>\u4f18\u5148\u7ea7<\/th><th>\u63a8\u8350\u5199\u6cd5<\/th><th>\u9002\u7528\u573a\u666f<\/th><th>\u5907\u6ce8<\/th><\/tr><tr><td>1<\/td><td>&lt;button type=&#8221;button&#8221;&gt;<\/td><td>\u7eaf\u89e6\u53d1\u4e8b\u4ef6\uff08\u975e\u8df3\u8f6c\uff09<\/td><td>\u6700\u4f73<\/td><\/tr><tr><td>2<\/td><td>&lt;a href=&#8221;javascript:void(0)&#8221;&gt;<\/td><td>\u5fc5\u987b\u7528 a \u6807\u7b7e\uff08\u8001\u9879\u76ee\u517c\u5bb9\uff09<\/td><td>\u5e38\u89c1<\/td><\/tr><tr><td>3<\/td><td>&lt;a href=&#8221;#&#8221; onclick=&#8221;&#8230;&#8221;&gt; + preventDefault()<\/td><td>\u8fc7\u6e21\u65b9\u6848<\/td><td>\u53ef\u63a5\u53d7<\/td><\/tr><tr><td>4<\/td><td>&lt;a href=&#8221;#&#8221;&gt;<\/td><td>\u6545\u610f\u8981\u8df3\u5230\u9876\u90e8\uff08\u951a\u70b9\uff09<\/td><td>\u7279\u6b8a\u573a\u666f<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4e00\u53e5\u8bdd\u8bb0\u4f4f\uff1a<br>\u73b0\u4ee3\u5f00\u53d1\u4e2d\uff0c\u51e1\u662f\u201c\u70b9\u51fb\u53ea\u6267\u884c JS\u3001\u4e0d\u8df3\u8f6c\u201d\u7684\u6309\u94ae\uff0c\u4f18\u5148\u7528 &lt;button&gt;\uff0c\u5b9e\u5728\u8981\u7528 &lt;a&gt; \u5c31\u7528 javascript:void(0) \u6216 preventDefault()\u3002\u5982\u679c\u4f60\u6709\u5177\u4f53\u4ee3\u7801\u7247\u6bb5\u6216\u573a\u666f\u9700\u8981\u4f18\u5316\uff0c\u6b22\u8fce\u8d34\u51fa\u6765\uff0c\u6211\u53ef\u4ee5\u5e2e\u4f60\u6539\u6210\u66f4\u89c4\u8303\u7684\u5199\u6cd5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript \u4e2d javascript:void(0) \u7684\u7528\u6cd5\u53ca\u5e38\u89c1\u95ee\u9898&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/22\/javascriptvoid-0%e7%94%a8%e6%b3%95%e5%8f%8a%e5%b8%b8%e8%a7%81%e9%97%ae%e9%a2%98%e8%a7%a3%e6%9e%90\/\">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":[49],"tags":[],"class_list":["post-854","post","type-post","status-publish","format-standard","hentry","category-javascript"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/854","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=854"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/854\/revisions"}],"predecessor-version":[{"id":855,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/854\/revisions\/855"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}