{"id":12504,"date":"2023-11-28T22:56:23","date_gmt":"2023-11-28T14:56:23","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=12504"},"modified":"2023-11-29T22:29:50","modified_gmt":"2023-11-29T14:29:50","slug":"javascript-zhongjquery-zhong-zen-me-yang-bian-xie","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/javascript-zhongjquery-zhong-zen-me-yang-bian-xie\/","title":{"rendered":"JavaScript \u4e2d jQuery \u4e2d\u600e\u4e48\u6837\u7f16\u5199\u63d2\u4ef6\uff1f"},"content":{"rendered":"<p>\u5728 jQuery \u4e2d\u7f16\u5199\u63d2\u4ef6\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\uff0c\u53ef\u4ee5\u8ba9\u4f60\u5c01\u88c5\u7279\u5b9a\u529f\u80fd\u5e76\u91cd\u590d\u4f7f\u7528\u3002\u521b\u5efa jQuery \u63d2\u4ef6\u901a\u5e38\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u4e86\u89e3 jQuery \u547d\u540d\u7a7a\u95f4<\/strong>\uff1a<\/p>\n<ul>\n<li>\u63d2\u4ef6\u901a\u5e38\u88ab\u6dfb\u52a0\u5230 jQuery \u7684\u547d\u540d\u7a7a\u95f4\u4e2d\uff0c\u786e\u4fdd\u5b83\u4e0d\u4f1a\u4e0e\u5176\u4ed6\u5e93\u6216\u4ee3\u7801\u53d1\u751f\u51b2\u7a81\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u63d2\u4ef6\u540d\u4f1a\u4ee5 <code>$.fn<\/code> \u5f00\u5934\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u7f16\u5199\u63d2\u4ef6\u4ee3\u7801<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 <code>$.fn<\/code> \u6765\u4e3a jQuery \u539f\u578b\u6dfb\u52a0\u65b0\u7684\u65b9\u6cd5\uff0c\u4f7f\u5176\u80fd\u591f\u88ab jQuery \u5bf9\u8c61\u8c03\u7528\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">(function(<span class=\"katex math inline\">) {<\/span>.fn.myPlugin = function(options) {\n    \/\/ \u63d2\u4ef6\u903b\u8f91\u4ee3\u7801\n  };\n})(jQuery);\n<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528 <code>this<\/code> \u5173\u952e\u5b57<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5728\u63d2\u4ef6\u5185\u90e8\uff0c<code>this<\/code> \u5173\u952e\u5b57\u6307\u5411 jQuery \u5bf9\u8c61\uff0c\u53ef\u4ee5\u7528\u6765\u64cd\u4f5c\u8c03\u7528\u63d2\u4ef6\u7684 DOM \u5143\u7d20\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">(function(<span class=\"katex math inline\">) {<\/span>.fn.myPlugin = function(options) {\n    return this.each(function() {\n      \/\/ \u4f7f\u7528 this \u64cd\u4f5c DOM \u5143\u7d20\n      $(this).text('This is my plugin');\n    });\n  };\n})(jQuery);\n<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u652f\u6301\u9009\u9879\u53c2\u6570<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5141\u8bb8\u63d2\u4ef6\u901a\u8fc7\u4f20\u9012\u9009\u9879\u53c2\u6570\u6765\u5b9a\u5236\u5176\u884c\u4e3a\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">(function(<span class=\"katex math inline\">) {<\/span>.fn.myPlugin = function(options) {\n    const settings = $.extend({\n      \/\/ \u9ed8\u8ba4\u9009\u9879\n    }, options);\n\n    return this.each(function() {\n      \/\/ \u4f7f\u7528\u8bbe\u7f6e\u4e2d\u7684\u9009\u9879\n    });\n  };\n})(jQuery);\n<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u8c03\u7528\u63d2\u4ef6<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5728\u4f60\u7684\u4ee3\u7801\u4e2d\uff0c\u4f7f\u7528 jQuery \u9009\u62e9\u5668\u9009\u62e9\u76f8\u5e94\u7684\u5143\u7d20\uff0c\u7136\u540e\u8c03\u7528\u63d2\u4ef6\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-javascript\">$('#myElement').myPlugin({\n  \/\/ \u4f20\u9012\u9009\u9879\n});\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>\u8fd9\u4e9b\u6b65\u9aa4\u53ef\u4ee5\u8ba9\u4f60\u521b\u5efa\u4e00\u4e2a\u57fa\u672c\u7684 jQuery \u63d2\u4ef6\uff0c\u5b83\u53ef\u4ee5\u5728\u591a\u4e2a\u9879\u76ee\u4e2d\u91cd\u590d\u4f7f\u7528\uff0c\u5e76\u63d0\u4f9b\u53ef\u5b9a\u5236\u7684\u9009\u9879\u6765\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002\u521b\u5efa\u63d2\u4ef6\u9700\u8981\u4e00\u5b9a\u7684 jQuery \u548c JavaScript \u77e5\u8bc6\uff0c\u4f46\u80fd\u591f\u6781\u5927\u5730\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u91cd\u7528\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 jQuery \u4e2d\u7f16\u5199\u63d2\u4ef6\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\uff0c\u53ef\u4ee5\u8ba9\u4f60\u5c01\u88c5\u7279\u5b9a\u529f\u80fd\u5e76\u91cd\u590d\u4f7f\u7528\u3002\u521b\u5efa jQuery \u63d2\u4ef6\u901a\u5e38\u9075\u5faa [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[115],"tags":[],"class_list":["post-12504","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/12504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=12504"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/12504\/revisions"}],"predecessor-version":[{"id":13551,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/12504\/revisions\/13551"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=12504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=12504"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=12504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}