jquery.extend()用来扩展jquery中方法,实现插件。javascript
扩展jQuery静态方法.css
用法: $.test()html
上述两个虽然说叫详解,讲解都很简略,下面这篇好一点。java
jQuery.extend(object);为扩展jQuery类自己.为类添加新的方法。
jQuery.fn.extend(object);给jQuery对象添加方法。jquery
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>test</title> </head> <body> <h3 class="ye">默认</h3> <h3 class="ye">默认</h3> <h3 class="ye">默认</h3> <h3 class="ye">默认</h3> <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript"> jQuery.fn.myPlugin = function(options) { $options = $.extend( { html: "方法自带值", css: { "color": "red", "font-size":"14px" }}, options); return $(this).css({ "color": $options.css.color, }).html($options.html); } $('.ye').myPlugin({html:"新的内容",css:{"color":"green","font-size":"20px"}}); </script> </body> </html>