在我的自定義插件中添加$(document).click事件的正確位置在哪裏?
(function ($) {
$.fn.greenify = function(options) {
$(document).click(function (event) { // where do I add this?
alert('this id was clicked');
});
// 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));
$('#a,#b,#c').greenify({
// My settings goes here
});
如果'$()。greenify()'被調用了,它有意義嗎? –
是............ –
但'this.click(function(){})'而不是'document'? –