以下代码将创建一个带有方法的插件
(function ( $ ) {
$.fn.greenify = function( options ) {
// This is the easiest way to have default options.
var settings = $.extend({
// These are the defaults.
color: "#556b2f",
backgroundColor: "white"
}, options );
// Greenify the collection based on the settings variable.
return this.css({
color: settings.color,
backgroundColor: settings.backgroundColor
});
};
}( jQuery ));
我们可以这样使用:
$( "div" ).greenify({
color: "orange"
});
但我想知道这样的事情
<div class="pluginclass"></div>
然后这应该是根据插件在标记中使用类但不喜欢$('div').pluginclass();