使用$(本)這是我的代碼如何在自定義jQuery插件
$('#J_todayComm').myScroll({
ajaxUrl: $(this)
});
我想獲得$(this)
- >$('#J_todayComm')
,但它是$(doucmen)
我的插件代碼myScroll.js
$.fn.myScroll = function (options) {
var s = $.extend({
debug: false,
threshold: 65,
loading: false,
ajaxUrl: '',
ajaxMethod: 'GET',
ajaxData: {},
loadSuccess: function() {
},
template: function() {
console.error("Need Template");
}
}, options);
console.log(s.ajaxUrl); //I want it is $('#J_todayComm')
// jquery對象
var $self = this;
// 原生DOM對象
var self = this[0];
......
function getDate() {
if (!s.ajaxUrl) {
console.error('Need url');
return '';
}
$.ajax(s.ajaxUrl, {
method: s.ajaxMethod,
data: s.ajaxData,
dataType: 'json',
success: function (res) {
...
},
error: function() {
...
}
});
}
return $self;
};
如何編寫代碼? Thx大家。
Thx,你的靈感來自我 –