{"id":3259,"date":"2024-11-10T08:55:24","date_gmt":"2024-11-10T00:55:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3259\/"},"modified":"2024-11-10T08:55:24","modified_gmt":"2024-11-10T00:55:24","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88%e6%88%91%e7%9a%84-jquery-%e8%84%9a%e6%9c%ac%e5%9c%a8%e8%b0%83%e7%94%a8%e5%8c%bf%e5%90%8d%e5%87%bd%e6%95%b0%e6%97%b6%e6%8a%a5%e9%94%99%e4%ba%86%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3259\/","title":{"rendered":"\u4e3a\u4ec0\u4e48\u6211\u7684 jQuery \u811a\u672c\u5728\u8c03\u7528\u533f\u540d\u51fd\u6570\u65f6\u62a5\u9519\u4e86\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173102583659860.jpg\" class=\"aligncenter\" title=\"\u4e3a\u4ec0\u4e48\u6211\u7684 jQuery \u811a\u672c\u5728\u8c03\u7528\u533f\u540d\u51fd\u6570\u65f6\u62a5\u9519\u4e86\uff1f\u63d2\u56fe\" alt=\"\u4e3a\u4ec0\u4e48\u6211\u7684 jQuery \u811a\u672c\u5728\u8c03\u7528\u533f\u540d\u51fd\u6570\u65f6\u62a5\u9519\u4e86\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>js \u5927\u4f6c\u7684\u56f0\u60d1\uff1ajquery \u811a\u672c\u62a5\u9519\u4e86<\/strong><\/p>\n<p>\u5728\u7f16\u5199\u4e00\u4e2a jquery \u811a\u672c\u65f6\uff0c\u4e00\u4f4d\u8d44\u6df1\u5f00\u53d1\u4eba\u5458\u5374\u610f\u5916\u5730\u9047\u5230\u4e86\u9519\u8bef\u3002\u811a\u672c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>&lt;!doctype html&gt;\n&lt;html ng-app=\"app\"&gt;\n&lt;head&gt;\n    &lt;script src=\"http:\/\/code.jquery.com\/jquery-latest.js\"&gt;&lt;\/script&gt;\n    &lt;script&gt;\n        $(function () {\n            var temp = new a();\n            temp.b();\n        })\n        var a = function () {\n            var b = function () {\n                alert(1);\n            }\n        }\n    &lt;\/script&gt;\n\n&lt;\/head&gt;\n&lt;\/html&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u56f0\u60d1\u7684\u5f00\u53d1\u4eba\u5458\u5c1d\u8bd5\u8fd0\u884c\u811a\u672c\uff0c\u5374\u6536\u5230\u4e86\u4e00\u6761\u9519\u8bef\u6d88\u606f\u3002\u7ecf\u8fc7\u4e00\u756a\u4ed4\u7ec6\u68c0\u67e5\uff0c\u4ed6\u65e0\u6cd5\u67e5\u660e\u95ee\u9898\u51fa\u5728\u54ea\u91cc\u3002<\/p>\n<p><strong>\u7b54\u6848\uff1a\u533f\u540d\u51fd\u6570\u7684 scope<\/strong><\/p>\n<p>\u7ecf\u8fc7\u4ed4\u7ec6\u5206\u6790\uff0c\u95ee\u9898\u7684\u6839\u6e90\u5728\u4e8e\u5bf9\u533f\u540d\u51fd\u6570 scope \u7684\u8bef\u89e3\u3002\u5728\u7ed9\u51fa\u7684\u4ee3\u7801\u4e2d\uff0c\u533f\u540d\u51fd\u6570 b \u88ab\u5b9a\u4e49\u5728\u51fd\u6570 a \u7684\u5185\u90e8\u3002\u4f46\u662f\uff0c\u8be5\u51fd\u6570\u4e0d\u662f\u4f5c\u4e3a a \u7684\u65b9\u6cd5\u521b\u5efa\u7684\uff0c\u800c\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u51fd\u6570\u3002<\/p>\n<p>\u8fd9\u610f\u5473\u7740\u5f53\u5b9e\u4f8b\u5316 a \u65f6\uff0c\u533f\u540d\u51fd\u6570 b \u65e0\u6cd5\u4f5c\u4e3a a \u7684\u65b9\u6cd5\u4f7f\u7528\u3002\u56e0\u6b64\uff0c\u8c03\u7528 temp.b() \u4f1a\u5bfc\u81f4\u9519\u8bef\uff0c\u56e0\u4e3a temp \u6ca1\u6709 b \u65b9\u6cd5\u3002<\/p>\n<p><strong>\u6b63\u786e\u7684\u5199\u6cd5<\/strong><\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u9700\u8981\u5c06\u533f\u540d\u51fd\u6570 b \u7ed1\u5b9a\u5230 this \u5173\u952e\u5b57\uff0c\u4ee5\u4fbf\u5b83\u6210\u4e3a a \u7684\u65b9\u6cd5\u3002\u6b63\u786e\u7684\u5199\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>var a = function () {\n    this.b = function () {\n        alert(1);\n    }\n}\n\nvar temp = new a();\ntemp.b();<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u6837\uff0cb \u51fd\u6570\u5c31\u4f5c\u4e3a a \u7684\u65b9\u6cd5\u7ed1\u5b9a\uff0c\u5e76\u4e14\u5f53\u5b9e\u4f8b\u5316 a \u65f6\uff0ctemp \u5c06\u83b7\u5f97 b \u65b9\u6cd5\u3002\u8fd0\u884c\u4fee\u6b63\u540e\u7684\u811a\u672c\u5c06\u6b63\u786e\u8f93\u51fa 1\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e3a\u4ec0\u4e48\u6211\u7684 jQuery \u811a\u672c\u5728\u8c03\u7528\u533f\u540d\u51fd\u6570\u65f6\u62a5\u9519\u4e86\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>js \u5927\u4f6c\u7684\u56f0\u60d1\uff1ajquery \u811a\u672c\u62a5\u9519\u4e86 \u5728\u7f16\u5199\u4e00\u4e2a jquery \u811a\u672c\u65f6\uff0c\u4e00\u4f4d\u8d44\u6df1\u5f00\u53d1\u4eba\u5458\u5374\u610f\u5916\u5730\u9047\u5230\u4e86\u9519\u8bef\u3002\u811a\u672c\u4ee3\u7801\u5982\u4e0b\uff1a &lt;!doctype html&gt; &lt;html ng-app=&#8221;app&#8221;&gt; &lt;head&gt; &lt;script src=&#8221;http:\/\/code.jquery.com\/jquery-latest.js&#8221;&gt;&lt;\/script&gt; &lt;script&gt; $(function () { var temp = new a(); temp.b(); }) var a = function () { var b = function () { alert(1); } } &lt;\/script&gt; &lt;\/head&gt; &lt;\/html&gt; \u767b\u5f55\u540e\u590d\u5236 \u56f0\u60d1\u7684\u5f00\u53d1\u4eba\u5458\u5c1d\u8bd5\u8fd0\u884c\u811a\u672c\uff0c\u5374\u6536\u5230\u4e86\u4e00\u6761\u9519\u8bef\u6d88\u606f\u3002\u7ecf\u8fc7\u4e00\u756a\u4ed4\u7ec6\u68c0\u67e5\uff0c\u4ed6\u65e0\u6cd5\u67e5\u660e\u95ee\u9898\u51fa\u5728\u54ea\u91cc\u3002 \u7b54\u6848\uff1a\u533f\u540d\u51fd\u6570\u7684 scope \u7ecf\u8fc7\u4ed4\u7ec6\u5206\u6790\uff0c\u95ee\u9898\u7684\u6839\u6e90\u5728\u4e8e\u5bf9\u533f\u540d\u51fd\u6570 scope \u7684\u8bef\u89e3\u3002\u5728\u7ed9\u51fa\u7684\u4ee3\u7801\u4e2d\uff0c\u533f\u540d\u51fd\u6570 b \u88ab\u5b9a\u4e49\u5728\u51fd\u6570 a \u7684\u5185\u90e8\u3002\u4f46\u662f\uff0c\u8be5\u51fd\u6570\u4e0d\u662f\u4f5c\u4e3a a \u7684\u65b9\u6cd5\u521b\u5efa\u7684\uff0c\u800c\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u51fd\u6570\u3002 [&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-3259","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3259","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=3259"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3259\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}