{"id":1611,"date":"2014-02-22T22:02:19","date_gmt":"2014-02-22T14:02:19","guid":{"rendered":"http:\/\/me.doucl.com\/?p=1611"},"modified":"2014-02-22T22:08:24","modified_gmt":"2014-02-22T14:08:24","slug":"jquery-extend-plugins","status":"publish","type":"post","link":"https:\/\/blog.vimge.com\/archives\/front-end\/jquery-extend-plugins.html","title":{"rendered":"jQuery\u63d2\u4ef6\u5f00\u53d1\u7684\u4e24\u79cd\u65b9\u6cd5"},"content":{"rendered":"
jQuery\u6dfb\u52a0\u63d2\u4ef6\u4e3b\u8981\u67092\u79cd\u65b9\u6cd5\uff1a<\/p>\n
\u4e00\u3001jquery.fn.extend(object) \u4e3ajQuery\u5bf9\u8c61\u6dfb\u52a0\u65b9\u6cd5<\/p>\n
jquery.fn \u5b9e\u9645\u4e0a\u5c31\u662fjquery.prototype\uff0c\u5982\u679c\u4ece\u8fd9\u4e2a\u89d2\u5ea6\u6765\u770b\u8bdd\uff0c\u5e94\u8be5\u53ef\u4ee5\u7406\u89e3 jquery.fn.extend(object)\u5b9e\u9645\u4e0a\u662f\u5bf9jquery.prototype\u8fdb\u884c\u6269\u5c55\uff0c\u5c31\u662f\u4e3ajQuery\u7c7b\u6dfb\u52a0\u201c\u6210\u5458\u51fd\u6570\u201d\uff0cjquery\u5b9e\u4f8b\u5bf9\u8c61\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u8be5\u65b9\u6cd5\u3002\u8fd9\u79cd\u65b9\u5f0f\u6dfb\u52a0\u7684\u65b9\u6cd5\u53ef\u4ee5\u901a\u8fc7jquery\u5b9e\u4f8b\u8fdb\u884c\u8c03\u7528\uff0c\u5982\uff1a$(“.className”).foo();<\/p>\n
\u4e8c\u3001jquery.extend(object) \u4e3a\u6269\u5c55jQuery\u672c\u8eab\u6dfb\u52a0\u65b9\u6cd5\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u7ed9jquery\u7c7b\u6dfb\u52a0\u201c\u9759\u6001\u65b9\u6cd5\u201d\uff0c\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u6dfb\u52a0\u7684\u65b9\u6cd5\u91c7\u7528\u8fd9\u79cd\u65b9\u5f0f\u8fdb\u884c\u8c03\u7528\uff0c$.foo();<\/p>\n
\u53e6\u5916\uff0c\u7ed3\u5408\u547d\u540d\u7a7a\u95f4\u548c\u95ed\u5305\uff08\u81ea\u6267\u884c\u533f\u540d\u51fd\u6570\uff09\u7279\u6027\u8fd8\u53ef\u4ee5\u8fdb\u884c\u6269\u5c55\uff0c\u4e3a\u63d2\u4ef6\u6dfb\u52a0\u4e00\u4e9b\u516c\u6709\u6216\u79c1\u6709\u7684\u65b9\u6cd5\u548c\u5c5e\u6027\uff0c\u5982<\/p>\n
\n(function($){\r\n \/\/\u5b9a\u4e49\u79c1\u6709\u65b9\u6cd5\r\n function foo(){\r\n \/\/foo function\r\n }\r\n\t\/\/\u4ee5\u4e0b\u5b9a\u4e49\u7684\u4e3ajQuery\u5168\u5c40\u65b9\u6cd5\uff0c\u8c03\u7528\u65b9\u5f0f\u4e3a $.foo();\r\n\t$.extend({\r\n\t\tfoo : function(){\r\n\t\t\t\/\/foo function\r\n\t\t}\r\n\t});\r\n\r\n\t\/\/\u4ee5\u4e0b\u65b9\u6cd5\u8c03\u7528\u65b9\u5f0f\u4e3a $().myPlug.foo();\r\n\t$.fn.extned({\r\n\t\tmyPlug : {\r\n\t\t\tfoo : function(){\r\n\t\t\t\t\/\/foo function\r\n\t\t\t},\r\n\t\t\tdoo : function(){\r\n\t\t\t\t\/\/ doo function\r\n\t\t\t}\r\n\t\t}\r\n\t});\r\n}){jQuery};<\/pre>\n<\/blockquote>\n\u5f15\u7528\u8d44\u6599\uff1a
\nhttp:\/\/learn.jquery.com\/plugins\/
\nhttp:\/\/www.iteye.com\/topic\/545971<\/p>\n","protected":false},"excerpt":{"rendered":"jQuery\u6dfb\u52a0\u63d2\u4ef6\u4e3b\u8981\u67092\u79cd\u65b9\u6cd5\uff1a \u4e00\u3001jquery.fn.extend(object) \u4e3ajQuery\u5bf9\u8c61 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[116,117],"_links":{"self":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1611"}],"collection":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/comments?post=1611"}],"version-history":[{"count":3,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1611\/revisions"}],"predecessor-version":[{"id":1613,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/posts\/1611\/revisions\/1613"}],"wp:attachment":[{"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/media?parent=1611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/categories?post=1611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.vimge.com\/wp-json\/wp\/v2\/tags?post=1611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}