次のようなプラグインがあります。
(function($){
$.fn.extend({
myplugin: function () {
var jobs = [];
this.each(function(){
jobs.push($(this).one(
'load',
function(){
// Line A: "Load" fires here
// Replace image source
$(this).attr('src','new_url');
// Line B: Everything is done, fire now!
}));
});
// Callback
$.when.apply(null,jobs).then(function(){
alert($(this).attr('src'));
});
return this;
}
});
})(jQuery);
when
ヘルパーは常に古いイメージ ソースを警告します。Line Aで呼び出されているためload
です。しかし、 Line Bで起動する必要があります。
これを解決するには?何か案は?
ありがとうございました!