{"id":4101,"date":"2024-11-10T16:44:22","date_gmt":"2024-11-10T08:44:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/4101\/"},"modified":"2024-11-10T16:44:22","modified_gmt":"2024-11-10T08:44:22","slug":"javascript-%e4%b8%ad%e7%9a%84%e5%87%bd%e6%95%b0%e5%a3%b0%e6%98%8e%ef%bc%9ageteventfunction-%e5%92%8c-var-fn-function-%e6%9c%89%e4%bb%80%e4%b9%88%e5%8c%ba%e5%88%ab%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/4101\/","title":{"rendered":"JavaScript \u4e2d\u7684\u51fd\u6570\u58f0\u660e\uff1agetevent:function() \u548c var fn = function() \u6709\u4ec0\u4e48\u533a\u522b\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173122526963221.jpg\" class=\"aligncenter\" title=\"JavaScript \u4e2d\u7684\u51fd\u6570\u58f0\u660e\uff1agetevent:function() \u548c var fn = function() \u6709\u4ec0\u4e48\u533a\u522b\uff1f\u63d2\u56fe\" alt=\"JavaScript \u4e2d\u7684\u51fd\u6570\u58f0\u660e\uff1agetevent:function() \u548c var fn = function() \u6709\u4ec0\u4e48\u533a\u522b\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>function \u7684\u4e0d\u540c\u5199\u6cd5<\/strong><\/p>\n<p>\u5728 javascript \u4e2d\uff0cfunction \u53ef\u4ee5\u6709\u591a\u79cd\u4e0d\u540c\u7684\u5199\u6cd5\u3002\u6211\u4eec\u8fd9\u91cc\u63a2\u8ba8\u4e24\u79cd\u5e38\u89c1\u7684\u65b9\u5f0f\uff0c\u5373 getevent:function() \u548c var fn = function()\u3002<\/p>\n<p><strong>getevent:function()<\/strong><\/p>\n<p>\u8fd9\u79cd\u5199\u6cd5\u662f\u58f0\u660e\u4e00\u4e2a\u533f\u540d\u51fd\u6570\u3002\u533f\u540d\u51fd\u6570\u6ca1\u6709\u540d\u79f0\uff0c\u56e0\u6b64\u4e0d\u80fd\u91cd\u590d\u4f7f\u7528\u3002\u5b83\u901a\u5e38\u7528\u4e8e\u4e00\u6b21\u6027\u64cd\u4f5c\u4e2d\uff0c\u4f8b\u5982\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>document.getevent(\"click\", function() {\n  \/\/ \u6b64\u51fd\u6570\u53ea\u6267\u884c\u4e00\u6b21\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>var fn = function()<\/strong><\/p>\n<p>\u8fd9\u79cd\u5199\u6cd5\u662f\u58f0\u660e\u4e00\u4e2a\u5e26\u540d\u79f0\u7684\u51fd\u6570\u3002\u5e26\u540d\u79f0\u7684\u51fd\u6570\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\uff0c\u4fbf\u4e8e\u7ba1\u7406\u548c\u7ef4\u62a4\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>var test = function() {\n  return \"\u56ed\";\n};\nalert(test());<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f55\u65f6\u4f7f\u7528\u54ea\u4e00\u79cd\u5199\u6cd5<\/strong><\/p>\n<p>\u9009\u62e9\u54ea\u79cd\u5199\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u60c5\u51b5\u3002\u4e00\u822c\u6765\u8bf4\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u9700\u8981\u4e00\u4e2a\u4e00\u6b21\u6027\u7684\u3001\u533f\u540d\u7684\u51fd\u6570\uff0c\u8bf7\u4f7f\u7528 getevent:function().<\/li>\n<li>\u5982\u679c\u9700\u8981\u4e00\u4e2a\u53ef\u91cd\u590d\u4f7f\u7528\u7684\u51fd\u6570\uff0c\u8bf7\u4f7f\u7528 var fn = function().<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fJavaScript \u4e2d\u7684\u51fd\u6570\u58f0\u660e\uff1agetevent:function() \u548c var fn = function() \u6709\u4ec0\u4e48\uff1f\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>function \u7684\u4e0d\u540c\u5199\u6cd5 \u5728 javascript \u4e2d\uff0cfunction \u53ef\u4ee5\u6709\u591a\u79cd\u4e0d\u540c\u7684\u5199\u6cd5\u3002\u6211\u4eec\u8fd9\u91cc\u63a2\u8ba8\u4e24\u79cd\u5e38\u89c1\u7684\u65b9\u5f0f\uff0c\u5373 getevent:function() \u548c var fn = function()\u3002 getevent:function() \u8fd9\u79cd\u5199\u6cd5\u662f\u58f0\u660e\u4e00\u4e2a\u533f\u540d\u51fd\u6570\u3002\u533f\u540d\u51fd\u6570\u6ca1\u6709\u540d\u79f0\uff0c\u56e0\u6b64\u4e0d\u80fd\u91cd\u590d\u4f7f\u7528\u3002\u5b83\u901a\u5e38\u7528\u4e8e\u4e00\u6b21\u6027\u64cd\u4f5c\u4e2d\uff0c\u4f8b\u5982\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b document.getevent(&#8220;click&#8221;, function() { \/\/ \u6b64\u51fd\u6570\u53ea\u6267\u884c\u4e00\u6b21 }); \u767b\u5f55\u540e\u590d\u5236 var fn = function() \u8fd9\u79cd\u5199\u6cd5\u662f\u58f0\u660e\u4e00\u4e2a\u5e26\u540d\u79f0\u7684\u51fd\u6570\u3002\u5e26\u540d\u79f0\u7684\u51fd\u6570\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\uff0c\u4fbf\u4e8e\u7ba1\u7406\u548c\u7ef4\u62a4\u3002\u4f8b\u5982\uff1a var test = function() { return &#8220;\u56ed&#8221;; }; alert(test()); \u767b\u5f55\u540e\u590d\u5236 \u4f55\u65f6\u4f7f\u7528\u54ea\u4e00\u79cd\u5199\u6cd5 \u9009\u62e9\u54ea\u79cd\u5199\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u60c5\u51b5\u3002\u4e00\u822c\u6765\u8bf4\uff1a \u5982\u679c\u9700\u8981\u4e00\u4e2a\u4e00\u6b21\u6027\u7684\u3001\u533f\u540d\u7684\u51fd\u6570\uff0c\u8bf7\u4f7f\u7528 getevent:function(). \u5982\u679c\u9700\u8981\u4e00\u4e2a\u53ef\u91cd\u590d\u4f7f\u7528\u7684\u51fd\u6570\uff0c\u8bf7\u4f7f\u7528 var fn = function(). \u4ee5\u4e0a\u5c31\u662fJavaScript \u4e2d\u7684\u51fd\u6570\u58f0\u660e\uff1agetevent:function() \u548c var fn = function() \u6709\u4ec0\u4e48\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-4101","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4101","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=4101"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4101\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=4101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=4101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=4101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}