我有一些代码在我的jQuery插件中创建了一个div但是add函数不起作用,它将css添加到页面上的所有元素。
我想在使用<div>
时在我调用插件的元素中创建$('element').initResource({});
。我该怎么做?
(function ( $ )
{
var initResource = function (options, element)
{
this.test();
this.options = $.extend(this.defaults, options);
this.el = element;
this.renderFilters();
};
initResource.prototype =
{
constructor: initResource,
options: {},
defaults:
{
base_url: '',
intended_action: 'link',
group_div: '',
used_filters: [],
data_type: 'student'
},
el: null,
addPanel: function ()
{
var panel = this.el.add("p"); // doesnt work
panel.css({
"border": "1px solid cornflowerblue",
"border-radius": "4px",
"margin-left": "5px",
"margin-right": "5px",
"margin-bottom": "15px",
"padding-top": "5px"
});
return panel;
},
renderFilters: function ()
{
var filters = this.addPanel.add('div'); // doesnt work
},
};
$.fn.initResource = function(options)
{
var iR = new initResource(options, this);
};
}( jQuery ));